I have an Activity which contains a fragment. I am requesting contact permission from the activity as follows:
ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.READ_CONTACTS}, REQUEST_CODE_PERMISSION);
requestPermissions(new String[] {Manifest.permission.CAMERA}, REQUEST_CODE_PERMISSION);
onRequestPermissionsResult
onRequestPermissionsResult
onRequestPermissionsResult
onRequestPermissionsResult
onRequestPermissionsResult
Be sure to call super.onRequestPermissionsResult(...)
when you overrides the method in your Activity
.
That said, one other way to solve this is to manually notify the Fragment
s that you have within your activity:
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
final List<Fragment> fragments = getSupportFragmentManager().getFragments();
if (fragments != null) {
for (Fragment fragment : fragments) {
fragment.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}
..and just have your fragments respond by doing the appropriate action if the requestCode
sent is theirs.