In my application there is a facility to capture image by using Camera. Its working perfectly for all the versions until Android 6,But it make my app crashed in Android version 7.0.
Manifest
<uses-permission android:name="android.permission.CAMERA" />
Permission added
if (ContextCompat.checkSelfPermission(AddFamilyMemberActivity.this,
android.Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(AddFamilyMemberActivity.this,
new String[]{android.Manifest.permission.CAMERA},
1);
} else {
sendToExternalApp();
}
Permission Listener
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == 1 && permissions[0].equals(android.Manifest.permission.CAMERA) &&
grantResults[0] == PackageManager.PERMISSION_GRANTED) {
sendToExternalApp();
} else if (requestCode == 1 && permissions[0].equals(android.Manifest.permission.CAMERA) &&
grantResults[0] == PackageManager.PERMISSION_DENIED) {
Utilities.showSnackBar("You need to enable camera permission for update profile image", this);
}
}
Code to open camera
protected void sendToExternalApp()
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mProcessingPhotoUri = getImageFile();
intent.putExtra(MediaStore.EXTRA_OUTPUT, mProcessingPhotoUri);
activity.startActivityForResult(intent, REQUEST_CODE_SELECT_IMAGE);
}
Crash log
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 clip={text/uri-list U:file:///storage/emulated/0/DCIM/QDhealth/profile.jpg} (has extras) }