Hi I am asking camera permission in android from my fragment using following code :
ActivityCompat.requestPermissions(getActivity(),
new String[]{Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE},
MainActivity.PROFILEIMAGE_REQUEST);
Then handling the permission result in same fragment using following code :
case MainActivity.PROFILEIMAGE_REQUEST: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED ) {
Log.e("Fragment","In OnRequestPermission onRequestPermissionsResult");
dispatchTakePictureIntent(MainActivity.PROFILEIMAGE_REQUEST); }
return;
}
Now when I run application for first time it asks the camera permission when as soon as I click on allow my application crashes in background then I see permission box for storage.
Also code in MainActivity :
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
List<Fragment> fragments = getSupportFragmentManager().getFragments();
Log.e("MainActivity", "In OnRequestPermission 1");
if (fragments != null) {
for (Fragment fragment : fragments) {
switch (requestCode) {
.
.
.
case PROFILEIMAGE_REQUEST:
if (fragment instanceof ProfileFragment) {
fragment.onRequestPermissionsResult(requestCode, permissions, grantResults);
Log.e("MainActivity","In OnRequestPermission PROFILEIMAGE_REQUEST");
return;
}
break;
.
.
.
.
.
}
}
}
Unable to get the logs for crash following stack trace is coming when I see the warning filtered logs :
W/ActivityManager: Force removing ActivityRecord{b66a7b9 u0 com.bootinfotech.queue.patient/com.indexnine.patient.activity.MainActivity t160}: app died, no saved state
Also I am unable to get exact error which causes the application to fail. What might have gone wrong. Device used for testing Moto G4 (Android M).
Also debugger is disconnected as soon as I click on allow for camera permission system dialog box.