Skip to content

Commit

Permalink
Merge pull request #14 from spoonconsulting/fix-android-13-permission
Browse files Browse the repository at this point in the history
Fix Android 13 Permission
  • Loading branch information
zfir authored Feb 27, 2023
2 parents b0d878f + fdc69ca commit dd05e27
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@
</feature>
</config-file>

<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
</config-file>

<framework src="com.android.support:appcompat-v7:27.1.1" />

<source-file src="src/android/ImagePicker.java" target-dir="src/com/spoon/imagepicker" />
Expand Down
9 changes: 7 additions & 2 deletions src/android/ImagePicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,18 @@ public void onRequestPermissionResult(int requestCode, String[] permissions, int
@SuppressLint("InlinedApi")
private boolean hasReadPermission() {
return Build.VERSION.SDK_INT < 23 ||
PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(this.cordova.getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE);
PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(this.cordova.getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE) ||
PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(this.cordova.getActivity(), Manifest.permission.READ_MEDIA_IMAGES);
}

@SuppressLint("InlinedApi")
private void requestReadPermission() {
if (!hasReadPermission()) {
cordova.requestPermissions(this, PERMISSION_REQUEST_CODE, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE});
if (Build.VERSION.SDK_INT < 33) {
cordova.requestPermissions(this, PERMISSION_REQUEST_CODE, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE});
} else {
cordova.requestPermissions(this, PERMISSION_REQUEST_CODE, new String[]{Manifest.permission.READ_MEDIA_IMAGES});
}
return;
}
callbackContext.success(1);
Expand Down

0 comments on commit dd05e27

Please sign in to comment.