I am writing my first App. I am using KitKat and an Experia Z for testing. My app will display photos that have been previously taken by the app.
I have been going round in ever decreasing circles, searching and trying, but never succeeding. I realise that I am possibly asking a duplicate question, but I have been unable to find it - and hence, the answer I need.
My starting point was from the Getting Started tutorials: http://developer.android.com/training/camera/photobasics.html
I create the Intent using:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
I can get hold of the small image using:
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) data.getExtras().get("data");
BTW, I have just noticed that all my test photos taken this way are visible the 'Album' app, and have the traditional file path in a camera, such as '/storage/sdcard1/DCIM/100ANDRO/DSC_0120.jpg'
Is there a way to get hold of this file path (in the onActivityResult() method)?
When I provide a file system URI, using:
File storageDir =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File photoFile = new File(storageDir, "test.jpg");
mCurrentPhotoPath = "file:" + photoFile.getAbsolutePath();
The path for 'storageDir' displays as: "/storage/emulated/0/Pictures". Which looks like some kind of temporary or logical location.
I add an 'extra' to the intent:
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
However, when I try to get the photo, it is never found (and it isn't in the standard camera file system, shown above)
bmOptions.inPurgeable = true;
Bitmap imBitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
The Bitmap imBitmap is null. Which suggest the the location in 'mCurrentPhotoPath' is not found.
AH! I don't know why 'mCurrentPhotoPath' is created with 'file:' as a prefix. I have removed it, and I now get my photo returned. (It was taken as portrait, but it is displayed across the ImageView, as if taken in landscape - no doubt that can handled).
However, I still don't know where it is. I have searched the phone and SD card using File Commander, and I can't find it. I would like to have the images stored in the same place as other photos, where they can be accessed by other apps.
Is there another step, whereby I ask for the image to be saved as a photo, so it gets the next file name in the 'DSC_nnnn.jpg' sequence? Or, as date-defined file path / name of my choice, on the same media defined for photos (internal or SD card)?
I would be really grateful for any help on this.
Regards, John
[edit 1]
Took phone to the beach - beach-weather days in the UK are a rare thing! This is my first Android phone - so I am in at the deep end.
In the relaxed conditions, I searched the phone using File Commander and, as stated in a reply, I found a 'Pictures' directory on the internal storage, and it contained the jpegs taken when I provided the location via the 'putExtra', and their location was as defined by Environment.DIRECTORY_PICTURES - so they are retrievable.
What I would prefer to happen is for the pictures to be placed wherever the Camera is set to store them - in my case this is on the SD card. This is what happens when I don't provide a target file location via 'putExtras' - which makes complete sense. I can get the thumbnail image using 'data.getExtras().get("data")'. Is there a way to get the file path for the actual image?
If that isn't possible, how can I get the location used by Camera on the SD card, in order to provide this as an Extra? All of the 'Environment.getXxxDir() methods look to return the internal storage.
[/edit 1]