@@ -103,29 +103,27 @@ public static boolean checkAndRequestCameraAndStoragePermissions(Activity activi
103
103
return checkAndRequestPermissions (activity , requestCode , getCameraAndStoragePermissions ());
104
104
}
105
105
106
- public static boolean checkAndRequestStoragePermission (Activity activity , int requestCode ) {
107
- return checkAndRequestPermissions (activity , requestCode , getStoragePermissions ());
108
- }
109
-
110
- public static boolean checkAndRequestStoragePermission (Fragment fragment , int requestCode ) {
111
- return checkAndRequestPermissions (fragment , requestCode , getStoragePermissions ());
106
+ public static boolean checkAndRequestFileDownloadPermission (Fragment fragment , int requestCode ) {
107
+ return checkAndRequestPermissions (fragment , requestCode , getFileDownloadPermission ());
112
108
}
113
109
114
110
public static String [] getCameraAndStoragePermissions () {
115
111
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
116
- return new String []{permission .CAMERA , permission . READ_MEDIA_IMAGES , permission . READ_MEDIA_VIDEO };
112
+ return new String []{permission .CAMERA };
117
113
} else if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
118
114
return new String []{permission .CAMERA , permission .READ_EXTERNAL_STORAGE };
119
115
} else {
120
116
return new String []{permission .CAMERA , permission .WRITE_EXTERNAL_STORAGE , permission .READ_EXTERNAL_STORAGE };
121
117
}
122
118
}
123
119
124
- private static String [] getStoragePermissions () {
125
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
126
- return new String []{permission .READ_MEDIA_IMAGES , permission .READ_MEDIA_VIDEO };
127
- } else if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
128
- return new String []{permission .READ_EXTERNAL_STORAGE };
120
+ /**
121
+ * Starting from Android Q (SDK 29), the WRITE_EXTERNAL_STORAGE permission is not needed anymore for downloading
122
+ * files when using DownloadManager.Request#setDestinationInExternalPublicDir.
123
+ */
124
+ private static String [] getFileDownloadPermission () {
125
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q ) {
126
+ return new String []{};
129
127
} else {
130
128
return new String []{permission .READ_EXTERNAL_STORAGE , permission .WRITE_EXTERNAL_STORAGE };
131
129
}
0 commit comments