onRequestPermissionsResult not being called in fragment if defined in both fragment and activity
Solution 1:
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:
- In AppCompatActivity use the method ActivityCompat.requestpermissions
- In v4 support fragment you should use requestpermissions
- Catch is if you call AppcompatActivity.requestpermissions in your fragment then callback will come to activity and not fragment
- Make sure to call
super.onRequestPermissionsResult
from the activity'sonRequestPermissionsResult
.
See if it helps .
Solution 2:
I requested location permission from a fragment and in the fragment, I needed to change this:
ActivityCompat.requestPermissions(getActivity(), new String[]{
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, LOCATION_REQ_CODE);
to this:
requestPermissions(new String[]{
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, LOCATION_REQ_CODE);
then the onRequestPermissionsResult was called in the fragment.