Allrounder
Allrounder

Reputation: 695

Camera intent creates the folder but does not save the image

In my camera intent of my app it creates the folder where i want to save the image, however it does not save the image.

here is my code i have so far:

 Intent getCameraImage = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
 getApplicationContext().getDir(
         getResources().getString(R.string.app_name), MODE_PRIVATE);

 File onsdcarddir = new File(Environment.getExternalStorageDirectory() +
         "/" +getResources().getString(R.string.app_name));

 if (!onsdcarddir.exists()) {
     onsdcarddir.mkdir(); // create dir here
 }
    startActivityForResult(getCameraImage, TAKE_PICTURE);

}    

What am i missing here? Could any one please help?

UPDATE

OnAcivityResult code:

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
 super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PICTURE && resultCode == RESULT_OK)
{
String bitmap = Environment.getExternalStorageDirectory()+"image.jpg";
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;;

Upvotes: 0

Views: 48

Answers (2)

Nitesh
Nitesh

Reputation: 3903

For saving different images you can change "image.jpg" to some dynamic name..

Uri imgUri = Uri.fromFile(new File((Environment.getExternalStorageDirectory() +
 "/" +getResources().getString(R.string.app_name), "image.jpg"));

to something like

Uri imgUri = Uri.fromFile(new File((Environment.getExternalStorageDirectory() +
 "/" +getResources().getString(R.string.app_name), new Date().getTime() + ".jpg"));

this will save every new image with the different timestamp as there name everytime, so will avoid the new images replacing the old ones.

Hop it helps you. :)

Upvotes: 1

Nitesh
Nitesh

Reputation: 3903

Try this,

Intent getCameraImage = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri imgUri = Uri.fromFile(new File((Environment.getExternalStorageDirectory() +
     "/" +getResources().getString(R.string.app_name), "image.jpg"));

getCameraImage.putExtra(MediaStore.EXTRA_OUTPUT, imgUri);
startActivityForResult(getCameraImage, TAKE_PICTURE);

Mark as up if it works for you.

Upvotes: 1

Related Questions