I have a fragment in which I have recyclerview and setting data in this recyclerview using recyclerview adapter.
Now, I am having a button in the adapter\'s list ite
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:
super.onRequestPermissionsResult
from the activity's onRequestPermissionsResult
.See if it helps .
The method requestPermissions
on Fragments requires API level 23 or higher.
If your app targets a lower version you can use
FragmentCompat.requestPermissions(this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
ConstantVariables.READ_EXTERNAL_STORAGE);
First you need to add the support-v13 dependency:
implementation "com.android.support:support-v13:$supportLibVersion"
Verify that both PERMISSION_REQUEST_CODE
inonRequestPermissionsResult
and inside yourFragment
contains the same value.
change this :
ActivityCompat.requestPermissions(
activity,
arrayOf(Manifest.permission.READ_CONTACTS),
PERMISSIONS_REQUEST_READ_CONTACTS
)
to this :
requestPermissions(
arrayOf(Manifest.permission.READ_CONTACTS),
PERMISSIONS_REQUEST_READ_CONTACTS
)
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
In fragment you shouldn't use ActivityCompat for requestPermissions and you just use requestPermissions and pass two parameters in method.
for exp :
requestPermissions(new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, STORAGE_PERMISSION_CODE);