Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixed android permissions callback
  • Loading branch information
Mevin Dhunnooa committed Nov 14, 2019
commit 146e76bb3c62c0688d0048b157d33d5549d1c31b
27 changes: 10 additions & 17 deletions src/android/com/synconset/ImagePicker/ImagePicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public class ImagePicker extends CordovaPlugin {

Expand Down Expand Up @@ -111,14 +111,10 @@ private boolean hasReadPermission() {
@SuppressLint("InlinedApi")
private void requestReadPermission() {
if (!hasReadPermission()) {
ActivityCompat.requestPermissions(
this.cordova.getActivity(),
new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},
PERMISSION_REQUEST_CODE);
cordova.requestPermissions(this, PERMISSION_REQUEST_CODE, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE});
return;
}
// This method executes async and we seem to have no known way to receive the result
// (that's why these methods were later added to Cordova), so simply returning ok now.
callbackContext.success();
callbackContext.success(1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tu aurais pu inverser la logique
if (hasReadPerm) {
...
} else {
...
}
pas besoin du return non plus

}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
Expand Down Expand Up @@ -155,19 +151,16 @@ public void onRestoreStateForActivityResult(Bundle state, CallbackContext callba
this.callbackContext = callbackContext;
}

/*

@Override
public void onRequestPermissionResult(int requestCode,
String[] permissions,
int[] grantResults) throws JSONException {
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException {

// For now we just have one permission, so things can be kept simple...
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
cordova.startActivityForResult(this, imagePickerIntent, 0);
callbackContext.success(1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on envoie 1 en cas de succès ? dans le else aussi c'est un cas de succès ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oui la method est successful, le 1/0 represente la statue de permission.

} else {
// Tell the JS layer that something went wrong...
callbackContext.error("Permission denied");
callbackContext.success(0);
}
}
*/

}