|
@@ -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;
|
|
@@ -21,9 +24,12 @@ import com.facebook.react.bridge.WritableMap;
|
21
|
24
|
import com.facebook.react.modules.network.ForwardingCookieHandler;
|
22
|
25
|
import com.facebook.react.modules.network.CookieJarContainer;
|
23
|
26
|
import com.facebook.react.modules.network.OkHttpClientProvider;
|
|
27
|
+import com.squareup.okhttp.OkHttpClient;
|
|
28
|
+
|
24
|
29
|
import okhttp3.OkHttpClient;
|
25
|
30
|
import okhttp3.JavaNetCookieJar;
|
26
|
31
|
|
|
32
|
+import java.io.File;
|
27
|
33
|
import java.util.HashMap;
|
28
|
34
|
import java.util.Map;
|
29
|
35
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
@@ -105,10 +111,29 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
|
105
|
111
|
@ReactMethod
|
106
|
112
|
public void actionViewIntent(String path, String mime, final Promise promise) {
|
107
|
113
|
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);
|
|
114
|
+ Uri uriForFile = FileProvider.getUriForFile(getCurrentActivity(),
|
|
115
|
+ this.getReactApplicationContext().getPackageName() + ".provider", new File(path));
|
|
116
|
+
|
|
117
|
+ if (Build.VERSION.SDK_INT >= 24) {
|
|
118
|
+ // Create the intent with data and type
|
|
119
|
+ Intent intent = new Intent(Intent.ACTION_VIEW)
|
|
120
|
+ .setDataAndType(uriForFile, mime);
|
|
121
|
+
|
|
122
|
+ // Set flag to give temporary permission to external app to use FileProvider
|
|
123
|
+ intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
124
|
+
|
|
125
|
+ // Validate that the device can open the file
|
|
126
|
+ PackageManager pm = getCurrentActivity().getPackageManager();
|
|
127
|
+ if (intent.resolveActivity(pm) != null) {
|
|
128
|
+ this.getReactApplicationContext().startActivity(intent);
|
|
129
|
+ }
|
|
130
|
+
|
|
131
|
+ } else {
|
|
132
|
+ Intent intent = new Intent(Intent.ACTION_VIEW)
|
|
133
|
+ .setDataAndType(Uri.parse("file://" + path), mime).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
134
|
+
|
|
135
|
+ this.getReactApplicationContext().startActivity(intent);
|
|
136
|
+ }
|
112
|
137
|
ActionViewVisible = true;
|
113
|
138
|
|
114
|
139
|
final LifecycleEventListener listener = new LifecycleEventListener() {
|