a-ferrari opened a new issue #1393:
URL: https://github.com/apache/cordova-android/issues/1393
# onRequestPermissionsResult never called after calling
cordova.requestPermissions
## Problem
api level version:<=29
After calling cordova.requestPermissions(this, 1, permissions) and give the
rights on the device, onRequestPermissionsResult isn't called
If I call cordova.requestPermission (without s) onRequestPermissionResult
(without s) is correctly called
## Information
<!-- Include all relevant information that might help understand and
reproduce the problem -->
### 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);
}
else
{
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();
/*
TODO
*/
}
}
```
### Environment, Platform, Device
<!-- In what environment, on what platform or on which device are you
experiencing the issue? -->
### 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
<!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
- [ X] I searched for existing GitHub issues: this problem is the same
reported same years ago https://github.com/eclipsesource/tabris-js/issues/898
- [ X] I updated all Cordova tooling to most recent version
- [ X] I included all the necessary information above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]