In my android app I employ a camera activity which sometimes works and sometimes doesn\'t. About 30% of the time the uri set up to store the photo comes back with a null va
Can anyone explain why this could happen
ACTION_IMAGE_CAPTURE
does not return a Uri
, according to the documentation. data.getData()
, in your code, should always be null
. If it is not null
, what that Uri
means is undocumented.
how to resolve it?
You already know what the Uri
is. You put it in EXTRA_OUTPUT
. Use that.
I didn't use to have this problem.
Yes, you did. There are thousands of Android device models. These ship with dozens, if not hundreds, of camera applications built in. There are dozens, if not hundreds, of additional ACTION_IMAGE_CAPTURE
-supporting apps available for download, from places like the Play Store. None of them have to return a Uri
, since the documentation does not say that they have to return a Uri
(and, even then, there are bugs in camera apps).
Thanks to CommonsWare I resolved the issue by implementing a onSaveInstance State. This should be required information on any android camera documentation as you lose the global variables whenever you change the camera's orientation.
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
// Save the user's current game state
savedInstanceState.putParcelable("myURI", imageUri);
// Always call the superclass so it can save the view hierarchy state
super.onSaveInstanceState(savedInstanceState);
}
public void onRestoreInstanceState(Bundle savedInstanceState) {
// Always call the superclass so it can restore the view hierarchy
super.onRestoreInstanceState(savedInstanceState);
// Restore state members from saved instance
imageUri = savedInstanceState.getParcelable("myURI");
}