Skip to content

Commit fe56a52

Browse files
authored
Merge pull request #58 from Auugustocesar/0.10.9
Bug Fix Branch 0.10.9 "...exposed beyond app through Intent.getData() " at Android N
2 parents 69a662a + c66788f commit fe56a52

File tree

4 files changed

+70
-10
lines changed

4 files changed

+70
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sat Aug 12 07:48:35 CEST 2017
1+
#Fri Jun 01 10:33:07 BRT 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
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

android/src/main/AndroidManifest.xml

+31-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.RNFetchBlob">
33

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" />
66

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>
735
</application>
836

9-
</manifest>
37+
</manifest>

android/src/main/java/com/RNFetchBlob/RNFetchBlob.java

+28-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import android.app.Activity;
44
import android.app.DownloadManager;
55
import android.content.Intent;
6+
import android.content.pm.PackageManager;
67
import android.net.Uri;
8+
import android.os.Build;
9+
import android.support.v4.content.FileProvider;
710
import android.util.SparseArray;
811

912
import com.facebook.react.bridge.ActivityEventListener;
@@ -24,6 +27,7 @@
2427
import okhttp3.OkHttpClient;
2528
import okhttp3.JavaNetCookieJar;
2629

30+
import java.io.File;
2731
import java.util.HashMap;
2832
import java.util.Map;
2933
import java.util.concurrent.LinkedBlockingQueue;
@@ -105,10 +109,29 @@ public void run() {
105109
@ReactMethod
106110
public void actionViewIntent(String path, String mime, final Promise promise) {
107111
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+
}
112135
ActionViewVisible = true;
113136

114137
final LifecycleEventListener listener = new LifecycleEventListener() {
@@ -382,4 +405,4 @@ public void getSDCardDir(Promise promise) {
382405
public void getSDCardApplicationDir(Promise promise) {
383406
RNFetchBlobFS.getSDCardApplicationDir(this.getReactApplicationContext(), promise);
384407
}
385-
}
408+
}
Original file line numberDiff line numberDiff line change
@@ -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>

0 commit comments

Comments
 (0)