I faced problem: ACTION_IMAGE_CAPTURE intent's behaviour depends on hardware manufacturer.
I think, best way to get photo from camera inserted in photo gallery must be something like following
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, CAPTURE_IMAGE_REQUEST);
and then get uri in onActivityResult
:
switch (requestCode) {
case CAPTURE_IMAGE_REQUEST: {
if(resultCode == Activity.RESULT_OK) {
Uri uri = intent.getData();// content uri of photo in media gallery
//do something with this
}
break;
}
But I see, that this doesn't work on many devices; moreover, I found several different scenarios of Camera app behaviour:
- some devices have bug with this event, so there is no way to get fullsized photos, and you can get 512px wide photo using tmp file in public directory only
- some devices (including mine) insert taken photo into gallery, but does not return Uri. (getData() returns null, intent extras have only boolean key 'specify-data', value = true) If I try to get photo through the public tempfile then photo will be inserted into both gallery and tempfile.
- some devices don't insert taken photos to gallery - and I must do it manually
- I dont know, but there can be other different scenarious
So, is there best practices in managing such problems to cover a wide range of devices and manufacturers?
In this case I need take photo from camera, get it inserted into gallery, then get uri of photo in gallery.