'Android 11<= resolveActivity
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 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | CommonsWare |
