Browse Source

fix(android): Updated permissions for Android Q and above (#1384 by @Karthz)

Karthik Subramaniam 4 years ago
parent
commit
03dbcb870e
No account linked to committer's email address

+ 2
- 2
android/gradle.properties View File

@@ -1,4 +1,4 @@
1 1
 ReactNativeWebView_kotlinVersion=1.3.50
2
-ReactNativeWebView_compileSdkVersion=28
3
-ReactNativeWebView_buildToolsVersion=28.0.3
2
+ReactNativeWebView_compileSdkVersion=29
3
+ReactNativeWebView_buildToolsVersion=29.0.3
4 4
 ReactNativeWebView_targetSdkVersion=28

+ 4
- 7
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewModule.java View File

@@ -272,16 +272,13 @@ public class RNCWebViewModule extends ReactContextBaseJavaModule implements Acti
272 272
   }
273 273
 
274 274
   public boolean grantFileDownloaderPermissions() {
275
-    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
275
+    // Permission not required for Android Q and above
276
+    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
276 277
       return true;
277 278
     }
278 279
 
279
-    boolean result = true;
280
-    if (ContextCompat.checkSelfPermission(getCurrentActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
281
-      result = false;
282
-    }
283
-
284
-    if (!result) {
280
+    boolean result = ContextCompat.checkSelfPermission(getCurrentActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
281
+    if (!result && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
285 282
       PermissionAwareActivity activity = getPermissionAwareActivity();
286 283
       activity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, FILE_DOWNLOAD_PERMISSION_REQUEST, webviewFileDownloaderPermissionListener);
287 284
     }

+ 2
- 2
docs/Guide.md View File

@@ -257,13 +257,13 @@ To be able to save images to the gallery you need to specify this permission in
257 257
 ##### Android
258 258
 
259 259
 On Android, integration with the DownloadManager is built-in.
260
-All you have to do to support downloads is add these permissions in AndroidManifest.xml:
260
+Add this permisison in AndroidManifest.xml (only required if your app supports Android versions lower than 10):
261 261
 
262 262
 ```xml
263 263
 <manifest ...>
264 264
   ......
265 265
 
266
-  <!-- this is required to save files on Android  -->
266
+  <!-- this is required to save files on Android versions lower than 10 -->
267 267
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
268 268
 
269 269
   ......

+ 2
- 2
example/android/build.gradle View File

@@ -2,9 +2,9 @@
2 2
 
3 3
 buildscript {
4 4
     ext {
5
-        buildToolsVersion = "28.0.3"
5
+        buildToolsVersion = "29.0.3"
6 6
         minSdkVersion = 16
7
-        compileSdkVersion = 28
7
+        compileSdkVersion = 29
8 8
         targetSdkVersion = 28
9 9
     }
10 10
     repositories {