Android M onRequestPermissionResult callback not being invoked in JAVA
See original GitHub issueJust installed a plugin that has a requestPermissions check method so that the permissions can be granted for android M before attempting to use the plugin.
When using tabris the JAVA onRequestPermissionResult callback is never invoked, and in turn the context.success is never invoked.
See offical docs for explanation https://developer.android.com/reference/android/support/v4/app/ActivityCompat.OnRequestPermissionsResultCallback.html
I’ve validated the same plugin works on vanilla Cordova Android 5.1.1 without issue.
Here is what I’ve found, others had this issue, but I’m not sure where to go from here.
1 Possibly needing Android Support Library 23.3.0 or greater http://stackoverflow.com/questions/33169455/onrequestpermissionsresult-not-being-called-in-dialog-fragment
2 Possibly related to fragments http://stackoverflow.com/questions/32714787/android-m-permissions-onrequestpermissionsresult-not-being-called
3 Tried both runOnUI and getThread pool, no dice.
cordova.getActivity().runOnUiThread(new Runnable() { })
cordova.getThreadPool().execute(new Runnable() { })
Here is the reduced version of the plugin.
class MyPermissionsPlugin extends CordovaPlugin {
private final int REQUEST_PERMISSIONS_TRACKING_NUMBER = 59888; // Random number to track the permission request
private CallbackContext permissionsCallback;
@Override
public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException {
if (action.equals("requestPermission")) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
requestPermissionAction(callbackContext);
}
});
return true;
}
return false;
}
public void requestPermissionAction(CallbackContext callbackContext) {
String[] permissions = {
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.RECEIVE_SMS,
Manifest.permission.READ_SMS,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.BLUETOOTH
};
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
callbackContext.error("This only applies to android M");
return;
}
permissionsCallback = callbackContext;
cordova.requestPermissions(this, REQUEST_PERMISSIONS_TRACKING_NUMBER, permissions);
}
// NOTE : this method never gets invoked
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException {
// NEVER MAKES IT HERE
if (permissionsCallback == null) {
return;
}
boolean hasPermission = cordova.hasPermission(Manifest.permission.READ_PHONE_STATE);
if (hasPermission) permissionsCallback.success("You have permission");
else permissionsCallback.error("You've been denied by the user");
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (5 by maintainers)
@exocom Select “Nightly” for Tabris.js version in build settings.
There shouldn’t be any changes on the JS side, but if you want the bleeding edge there too just update your
package.json
dependency fortabris
tohttps://tabrisjs.com/downloads/nightly/tabris.tgz
.@cookieguru and thanks for explaining the update path