Monday, July 22, 2019

java - Android M Permissions: onRequestPermissionsResult() not being called



I'm updating our app to use the new M Permissions system.
It is all working besides the onRequestPermissionsResult(). I need to check a permission on a button press, and if it is successful, send a text message. When I grant permission to do it, the dialog closes, but it doesn't trigger the Send Text until I press the button again.



I've debugged and set breakpoints in the onRequestPermissionsResult() method but it never goes into it.




This method gets called first:



    private void askForPermission() {
String[] permissions = new String[]{Manifest.permission.SEND_SMS};
ActivityCompat.requestPermissions(getActivity(), permissions, PERMISSIONS_CODE);
}


And then my callback looks like this:




    @Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);

if (requestCode == PERMISSIONS_CODE) {
for (int i = 0; i < permissions.length; i++) {
String permission = permissions[i];
int grantResult = grantResults[i];

if (permission.equals(Manifest.permission.SEND_SMS)) {

if (grantResult == PackageManager.PERMISSION_GRANTED) {
onPPSButtonPress();
} else {
requestPermissions(new String[]{Manifest.permission.SEND_SMS}, PERMISSIONS_CODE);
}
}
}
}
}



Has anybody ran into a similar issue?
Appreciate any help with this.
Thanks


Answer



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


No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...