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:
- 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 .
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 checkonRequestPermissionsResult()
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
Programmatically Adding Tablerow to Tablelayout Not Working
Simple Example for Intent and Bundle
A Way to Get Unlock Event in Android
How to Dynamically Remove Items from Listview on a Button Click
In Androidx.Fragment.App.Fragment,Setuservisiblehint()Is Deprecated,And Not Executed,Why
Action_Sendto for Sending an Email
Programmatic Views How to Set Unique Id'S
Multi Selection Spinner in Android Without Alertdialog
Android: Can You Nest Fragments
Problem to Load Flv Video in Webview
Android Setting with Textview for Hebrew Text
Error:Execution Failed For Task ':App:Transformclasseswithjarmergingfordebug'