Issue
I work on improvement functionality for android app. There is a feature for making photo from app. And for andorid 11<=
takePictureIntent.resolveActivity(getPackageManager())
returns null. I know it's because of higher android version. But when I removed if statement everything working so I wonder why this line was there and what wrong could happened if it will be removed.
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
//if (true) {
File photoFile = createImageFile();
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
Solution
If there is no matching activity, your startActivityForResult()
call should crash with an ActivityNotFoundException
.
Wrapping the startActivityForResult()
call in a try
/catch
works for all Android versions.
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.