Pārlūkot izejas kodu

Merge pull request #58 from Auugustocesar/0.10.9

Bug Fix Branch 0.10.9 "...exposed beyond app through Intent.getData() " at Android N
Travis Nuttall 6 gadus atpakaļ
vecāks
revīzija
fe56a52322
No account linked to committer's email address

+ 2
- 2
android/gradle/wrapper/gradle-wrapper.properties Parādīt failu

@@ -1,6 +1,6 @@
1
-#Sat Aug 12 07:48:35 CEST 2017
1
+#Fri Jun 01 10:33:07 BRT 2018
2 2
 distributionBase=GRADLE_USER_HOME
3 3
 distributionPath=wrapper/dists
4 4
 zipStoreBase=GRADLE_USER_HOME
5 5
 zipStorePath=wrapper/dists
6
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
6
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

+ 31
- 3
android/src/main/AndroidManifest.xml Parādīt failu

@@ -1,9 +1,37 @@
1 1
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2 2
     package="com.RNFetchBlob">
3 3
 
4
-    <application
5
-        android:label="@string/app_name">
4
+    <!-- Required to access Google Play Licensing -->
5
+    <uses-permission android:name="com.android.vending.CHECK_LICENSE" />
6 6
 
7
+    <!-- Required to download files from Google Play -->
8
+    <uses-permission android:name="android.permission.INTERNET" />
9
+
10
+    <!-- Required to keep CPU alive while downloading files
11
+        (NOT to keep screen awake) -->
12
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
13
+
14
+    <!-- Required to poll the state of the network connection
15
+        and respond to changes -->
16
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
17
+
18
+    <!-- Required to check whether Wi-Fi is enabled -->
19
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
20
+
21
+    <!-- Required to read and write the expansion files on shared storage -->
22
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
23
+
24
+    <application android:label="@string/app_name">
25
+
26
+        <provider
27
+            android:name="android.support.v4.content.FileProvider"
28
+            android:authorities="${applicationId}.provider"
29
+            android:exported="false"
30
+            android:grantUriPermissions="true">
31
+            <meta-data
32
+                android:name="android.support.FILE_PROVIDER_PATHS"
33
+                android:resource="@xml/provider_paths" />
34
+        </provider>
7 35
     </application>
8 36
 
9
-</manifest>
37
+</manifest>

+ 28
- 5
android/src/main/java/com/RNFetchBlob/RNFetchBlob.java Parādīt failu

@@ -3,7 +3,10 @@ package com.RNFetchBlob;
3 3
 import android.app.Activity;
4 4
 import android.app.DownloadManager;
5 5
 import android.content.Intent;
6
+import android.content.pm.PackageManager;
6 7
 import android.net.Uri;
8
+import android.os.Build;
9
+import android.support.v4.content.FileProvider;
7 10
 import android.util.SparseArray;
8 11
 
9 12
 import com.facebook.react.bridge.ActivityEventListener;
@@ -24,6 +27,7 @@ import com.facebook.react.modules.network.OkHttpClientProvider;
24 27
 import okhttp3.OkHttpClient;
25 28
 import okhttp3.JavaNetCookieJar;
26 29
 
30
+import java.io.File;
27 31
 import java.util.HashMap;
28 32
 import java.util.Map;
29 33
 import java.util.concurrent.LinkedBlockingQueue;
@@ -105,10 +109,29 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
105 109
     @ReactMethod
106 110
     public void actionViewIntent(String path, String mime, final Promise promise) {
107 111
         try {
108
-            Intent intent= new Intent(Intent.ACTION_VIEW)
109
-                    .setDataAndType(Uri.parse("file://" + path), mime);
110
-            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
111
-            this.getReactApplicationContext().startActivity(intent);
112
+            Uri uriForFile = FileProvider.getUriForFile(getCurrentActivity(),
113
+                    this.getReactApplicationContext().getPackageName() + ".provider", new File(path));
114
+
115
+            if (Build.VERSION.SDK_INT >= 24) {
116
+                // Create the intent with data and type
117
+                Intent intent = new Intent(Intent.ACTION_VIEW)
118
+                        .setDataAndType(uriForFile, mime);
119
+
120
+                // Set flag to give temporary permission to external app to use FileProvider
121
+                intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
122
+
123
+                // Validate that the device can open the file
124
+                PackageManager pm = getCurrentActivity().getPackageManager();
125
+                if (intent.resolveActivity(pm) != null) {
126
+                    this.getReactApplicationContext().startActivity(intent);
127
+                }
128
+
129
+            } else {
130
+                Intent intent = new Intent(Intent.ACTION_VIEW)
131
+                        .setDataAndType(Uri.parse("file://" + path), mime).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
132
+
133
+                this.getReactApplicationContext().startActivity(intent);
134
+            }
112 135
             ActionViewVisible = true;
113 136
 
114 137
             final LifecycleEventListener listener = new LifecycleEventListener() {
@@ -382,4 +405,4 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
382 405
     public void getSDCardApplicationDir(Promise promise) {
383 406
         RNFetchBlobFS.getSDCardApplicationDir(this.getReactApplicationContext(), promise);
384 407
     }
385
-}
408
+}

+ 9
- 0
android/src/main/res/xml/provider_paths.xml Parādīt failu

@@ -0,0 +1,9 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<paths xmlns:android="http://schemas.android.com/apk/res/android">
3
+    <external-path
4
+        name="external_files"
5
+        path="." />
6
+    <files-path
7
+        name="files-path"
8
+        path="." /> <!-- Used to access into application data files -->
9
+</paths>