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.
Android onRequestPermissionsResult not being called in fragment
The onRequestPermissionsResult
has to be catch in the activty
.
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 .
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 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.
Android M Permissions: onRequestPermissionsResult() not being called
This issue was actually being caused by NestedFragments.
Basically most fragments we have extend a HostedFragment which in turn extends a CompatFragment. Having these nested fragments caused issues which eventually were solved by another developer on the project.
He was doing some low level stuff like bit switching to get this working so I'm not too sure of the actual final solution
Related Topics
How to Start a New Android Activity Using Class Name in a String
Curly Braces in "New" Expression? (E.G. "New Myclass() { ... }")
Android App Bundle Introduces Resource Not Found Crash in Android App
Convert a String to a Byte Array and Then Back to the Original String
Setnavigationitemselectedlistener Not Working
Fatal Exception: Firebase-Messaging-Intent-Handle -- Java.Lang.Noclassdeffounderror
How to Remove Only Trailing Spaces of a String in Java and Keep Leading Spaces
How to Parse or Split Url Address in Java
Android Studio Mailto Intent Doesn't Show Subject and Mail Body
How Does One Configure Rjava on Osx to Select the Right Jvm -- .Jinit() Failing
How to Include the Spongy Castle Jar in Android
How to Change Size of Title's Text on Action Bar
Proguard and Reflection in Android
Listview Viewholder Checkbox State
When Onbindviewholder Is Called and How It Works
Google Signin API Exception 10
How to Override the Cipherlist Sent to the Server by Android When Using Httpsurlconnection