@@ -103,29 +103,27 @@ public static boolean checkAndRequestCameraAndStoragePermissions(Activity activi
103103 return checkAndRequestPermissions (activity , requestCode , getCameraAndStoragePermissions ());
104104 }
105105
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 ());
112108 }
113109
114110 public static String [] getCameraAndStoragePermissions () {
115111 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 };
117113 } else if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
118114 return new String []{permission .CAMERA , permission .READ_EXTERNAL_STORAGE };
119115 } else {
120116 return new String []{permission .CAMERA , permission .WRITE_EXTERNAL_STORAGE , permission .READ_EXTERNAL_STORAGE };
121117 }
122118 }
123119
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 []{};
129127 } else {
130128 return new String []{permission .READ_EXTERNAL_STORAGE , permission .WRITE_EXTERNAL_STORAGE };
131129 }
0 commit comments