I have started testing my app on a Moto E2, which is one of the first Android Lollipop devices on the marked. Turns out I'm unexpectedly having trouble capturing images with the camera. I cannot receive a picture.
Creating an image capture intent using:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, PICK_FROM_CAMERA);
Upon returning to my activity the Intent
contains no data, i.e. data.getData()
returns null.
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK) return;
switch(requestCode) {
case PICK_FROM_CAMERA:
(...)
}
}
On Moto E2 running Android 5.0.2:
Now there is a flood of questions on SO here with similar issues and a variety of different causes. What really puzzles me here is that this code works just fine on my other Android devices running KitKat and Jelly Bean (see below). What could be the reason for this behavior, and how can I fix it?
On Galaxy S4 mini running Android 4.4.2:
Android 5.0 has some extra filtering to handle the Intent
. Therefore, you might have to handle it this way. You can give it a try as it has been changed in Camera API for 5.0
Part of it is here
static final int REQUEST_IMAGE_CAPTURE = 1;
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
More details can be found in the documentation for Android 5.0 API changes.
https://developer.android.com/training/camera-deprecated/photobasics#TaskPath