This is an automated email from the ASF dual-hosted git repository.
erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-file.git
The following commit(s) were added to refs/heads/master by this push:
new 28c935c feat(android): add READ_MEDIA_* permissions for Android 13+
(#566)
28c935c is described below
commit 28c935cfceac09a194f94a71fb91a894657b001a
Author: MauriceFrank <[email protected]>
AuthorDate: Tue Jul 4 19:02:50 2023 +0200
feat(android): add READ_MEDIA_* permissions for Android 13+ (#566)
* Add READ_MEDIA - permissions for Android 13+
* Fix spelling in permssion string
---------
Co-authored-by: maurice.frank <[email protected]>
---
src/android/FileUtils.java | 32 ++++++++++++++++++++++++++++----
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 24c0a40..de973da 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -100,12 +100,25 @@ public class FileUtils extends CordovaPlugin {
private PendingRequests pendingRequests;
/*
- * We need both read and write when accessing the storage, I think.
+ * We need both read and write when accessing the storage, I think. (SDK
Version < 33)
+ *
+ * If your app targets Android 13 (SDK 33) or higher and needs to access
media files that other apps have created,
+ * you must request one or more of the following granular media
permissions
+ * instead of the READ_EXTERNAL_STORAGE permission:
+ *
+ * READ_MEDIA_IMAGES
+ * READ_MEDIA_VIDEO
+ * READ_MEDIA_AUDIO
+ *
+ * Refer to:
https://developer.android.com/about/versions/13/behavior-changes-13
*/
private String [] permissions = {
Manifest.permission.READ_EXTERNAL_STORAGE,
- Manifest.permission.WRITE_EXTERNAL_STORAGE };
+ Manifest.permission.WRITE_EXTERNAL_STORAGE,
+ Manifest.permission.READ_MEDIA_IMAGES,
+ Manifest.permission.READ_MEDIA_VIDEO,
+ Manifest.permission.READ_MEDIA_AUDIO};
// This field exists only to support getEntry, below, which has been
deprecated
private static FileUtils filePlugin;
@@ -577,7 +590,12 @@ public class FileUtils extends CordovaPlugin {
private void getReadPermission(String rawArgs, int action, CallbackContext
callbackContext) {
int requestCode = pendingRequests.createRequest(rawArgs, action,
callbackContext);
- PermissionHelper.requestPermission(this, requestCode,
Manifest.permission.READ_EXTERNAL_STORAGE);
+ if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
+ PermissionHelper.requestPermissions(this, requestCode,
+ new String[]{Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_VIDEO, Manifest.permission.READ_MEDIA_AUDIO});
+ } else {
+ PermissionHelper.requestPermission(this, requestCode,
Manifest.permission.READ_EXTERNAL_STORAGE);
+ }
}
private void getWritePermission(String rawArgs, int action,
CallbackContext callbackContext) {
@@ -586,7 +604,13 @@ public class FileUtils extends CordovaPlugin {
}
private boolean hasReadPermission() {
- return PermissionHelper.hasPermission(this,
Manifest.permission.READ_EXTERNAL_STORAGE);
+ if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
+ return PermissionHelper.hasPermission(this,
Manifest.permission.READ_MEDIA_IMAGES)
+ && PermissionHelper.hasPermission(this,
Manifest.permission.READ_MEDIA_VIDEO)
+ && PermissionHelper.hasPermission(this,
Manifest.permission.READ_MEDIA_AUDIO);
+ } else {
+ return PermissionHelper.hasPermission(this,
Manifest.permission.READ_EXTERNAL_STORAGE);
+ }
}
private boolean hasWritePermission() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]