添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
卖萌的青椒  ·  Access onCreate() ...·  1 周前    · 
坚韧的凉面  ·  Selection- Model List ...·  10 月前    · 
风流的火柴  ·  Issue with html ...·  11 月前    · 

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onRequestPermissionsResult never called after calling cordova.requestPermissions but it is called the deprecated method onRequestPermissionResult

Problem

api level version:<=29

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

Information

Command or Code

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