Onrequestpermissionsresult Not Being Called in Fragment If Defined in Both Fragment and Activity

onRequestPermissionsResult not being called in fragment if defined in both fragment and activity

Edited answer to cover broader issues

I think you are confusing the method for fragment and activity. Had a similar issue my project last month. Please check if you have finally the following:

  1. In AppCompatActivity use the method ActivityCompat.requestpermissions
  2. In v4 support fragment you should use requestpermissions
  3. Catch is if you call AppcompatActivity.requestpermissions in your fragment then callback will come to activity and not fragment
  4. Make sure to call super.onRequestPermissionsResult from the activity's onRequestPermissionsResult.

See if it helps .

Android onRequestPermissionsResult not being called in fragment

The onRequestPermissionsResult has to be catch in the activty.

onRequestPermissionsResult not called in fragment

When you called this in your fragment

getActivity().requestPermissions(new String[{Manifest.permission.READ_EXTERNAL_STORAGE},12);

then

 @Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
Log.i("permission", "Request Code: "+ requestCode);
}

is getting called in your activity where you are adding your fragment.

So requestPermissions() in fragment and check onRequestPermissionsResult() in you parent activity.where you are adding you fragment.

The Reason is requestPermissions needs an activity as aurgument Check Full details here.

onRequestPermissionsResult() not called in fragment, tried all solutions I could find

In your activity-level onRequestPermissionsResult(), handle any permission requests issued by the activity.

If the requestCode does not match one requested by the activity (e.g., in a default branch for a switch), chain to the superclass (super.onRequestPermissionsResult(requestCode, permissions, grantResults);). If you are not doing this, that might prevent FragmentActivity from routing results to a fragment, for fragment-initiated requests.

onRequestPermissionsResult not being called in dialog fragment

There appears to be a bug in Android, where nested fragments do not support the onRequestPermissionsResult() callback. For a DialogFragment, a workaround appears to be to have the fragment wanting to show the dialog call a method on the hosting activity, and the activity shows the DialogFragment itself.



Related Topics



Leave a reply



Submit