Using this piece of code is suggested and it states
Notice that the startActivityForResult() method is protected by a condition that calls resolveActivity(), which returns the first activity component that can handle the intent. Performing this check is important because if you call startActivityForResult() using an intent that no app can handle, your app will crash. So as long as the result is not null, it's safe to use the intent.
Code:
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
It works fine, but NOT on an Alcatel device running 4.2.2. I get the ELSE
message with my toast "Cannot use camera..."
How is this possible if a device has the camera?
What should I do now? How to handle this use case - obviously I have to rely that some devices with the camera will report "cannot use camera", detect that those devices have camera and then use it?!
The documentation or SO questions say nothing about the ELSE case.
How is this possible if a device has the camera?
The authors of the camera app pre-installed on that device failed to support the ACTION_IMAGE_CAPTURE
Intent
action. There are lots of bugs with camera apps.
While probably not relevant for your situation here, bear in mind that with restricted profiles on Android 4.3+, the current user of the device might not have access to an ACTION_IMAGE_CAPTURE
activity, even if the device happens to have one.
What should I do now?
Do something like:
Tell the user that they do not have a compatible camera app and steer them towards downloading one that you know works well with your app
Do not rely upon ACTION_IMAGE_CAPTURE
and instead embed photo-taking capability in your app
Disable the feature of your app that requires ACTION_IMAGE_CAPTURE
, on devices where resolveActivity()
returns null
Etc.