forked from Telerik-Verified-Plugins/ImagePicker
-
Notifications
You must be signed in to change notification settings - Fork 12
Fixed android permissions callback #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
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
Merged
Merged
Changes from all commits
Commits
File filter
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
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
|
||
|
|
@@ -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); | ||
| } | ||
|
|
||
| public void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
|
|
@@ -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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
| } | ||
| */ | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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