After calling cordova.requestPermissions(this, 1, permissions) and give the rights on the device, onRequestPermissionsResult isn't called ( but It is called onRequestPermissionResult that is deprecated)
If I call cordova.requestPermission (without s) onRequestPermissionResult (without s) is correctly called
package com.thesis.plugins;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.Manifest;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Environment;
import android.util.Base64;
import android.util.Log;
import android.provider.MediaStore;
import android.os.Build;
import android.content.ContentValues;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import android.widget.Toast;
* This class echoes a string called from JavaScript.
public class CordovaAndroidThesisStore extends CordovaPlugin {
private CallbackContext _tmpCallbackContext;
private JSONArray _tmpArgs;
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("store")) {
//String message = args.getString(0);
//cordova.getActivity().runOnUiThread(()
cordova.getThreadPool().execute(() -> {
try {
store(args, callbackContext);
} catch (JSONException e) {
e.printStackTrace();
return true;
return false;
private void store(JSONArray args, CallbackContext callbackContext) throws JSONException {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
this.store(args.getString(0), args.getString(1), callbackContext);
}else{
if(cordova.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE))
this.store(args.getString(0), args.getString(1), callbackContext);
this._tmpCallbackContext= callbackContext;
this._tmpArgs= args;
String [] permissions= {Manifest.permission.WRITE_EXTERNAL_STORAGE};
// cordova.requestPermissions(this, 1, permissions); DOSN'T WORK
cordova.requestPermission(this, 1, permissions[0]);
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions,
int[] grantResults) throws JSONException
for(int r:grantResults)
if(r == PackageManager.PERMISSION_DENIED)
this._tmpCallbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "NO_PERMISSION"));
return;
if(requestCode==1) {
this.store(_tmpArgs.getString(0), _tmpArgs.getString(1), _tmpCallbackContext);
@Override
public void onRequestPermissionResult(int requestCode, String[] permissions,
int[] grantResults) throws JSONException
for(int r:grantResults)
if(r == PackageManager.PERMISSION_DENIED)
this._tmpCallbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "NO_PERMISSION"));
return;
if(requestCode==1) {
this.store(_tmpArgs.getString(0), _tmpArgs.getString(1), _tmpCallbackContext);
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
protected void store(String byteString, String fileName, CallbackContext callbackContext) {
final CordovaInterface _cordova = cordova;
Context context = this.cordova.getActivity();
Toast toast = Toast.makeText(context, "YEAAA", Toast.LENGTH_LONG);
toast.show();
Environment, Platform, Device
Version information
Cordova Packages:
cli: 11.0.0
common: 4.0.2
create: 4.0.0
lib: 11.0.0
common: 4.0.2
fetch: 3.0.1
serve: 4.0.0
Project Installed Platforms:
android: 10.1.1
Project Installed Plugins:
com-thesis-plugins-pdfstore: 0.0.1
Environment:
OS: macOS Monterey 12.0.1 (21A559) (darwin 21.1.0) x64
Node: v12.14.0
npm: 6.14.5
Checklist
[ X] I searched for existing GitHub issues: this problem is the same reported same years ago Android M onRequestPermissionResult callback not being invoked in JAVA eclipsesource/tabris-js#898
[ X] I updated all Cordova tooling to most recent version
[ X] I included all the necessary information above
The reason is the implementation of onRequestPermissionResult in CordovaInterfaceImpl
* Called by the system when the user grants permissions
* @param requestCode
* @param permissions
* @param grantResults
public void onRequestPermissionResult(int requestCode, String[] permissions,
int[] grantResults) throws JSONException {
Pair<CordovaPlugin, Integer> callback = permissionResultCallbacks.getAndRemoveCallback(requestCode);
if(callback != null) {
callback.first.onRequestPermissionResult(callback.second, permissions, grantResults);
As noted in the comment, the former is deprecated in favour of the
latter, but the latter is never called. See also:
- apache/cordova-android#1388
- apache/cordova-android#1393
I hope the comment will help us fix the problem quickly when the Cordova
folks decide to remove the deprecated method. (And hopefully make sure
that the new method is called.)
Addresses: https://trello.com/c/zsmadleg/2549-mind-ease-notifications-probably-broken-on-android
As noted in the comment, the former is deprecated in favour of the
latter, but the latter is never called. See also:
- apache/cordova-android#1388
- apache/cordova-android#1393
I hope the comment will help us fix the problem quickly when the Cordova
folks decide to remove the deprecated method. (And hopefully make sure
that the new method is called.)
Addresses: https://trello.com/c/zsmadleg/2549-mind-ease-notifications-probably-broken-on-android