Skip to content

Commit 6100fcf

Browse files
Ron RadtkeRon Radtke
authored andcommitted
some merge fixes
1 parent a09694d commit 6100fcf

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

android.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const RNFetchBlob = NativeModules.RNFetchBlob
1414
* @return {Promise}
1515
*/
1616
function actionViewIntent(path, mime, chooserTitle) {
17+
if(typeof chooserTitle === 'undefined') chooserTitle = null;
1718
if(Platform.OS === 'android')
1819
return RNFetchBlob.actionViewIntent(path, mime, chooserTitle)
1920
else

android/src/main/AndroidManifest.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
2020

2121
<!-- Required to read and write the expansion files on shared storage -->
22-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
22+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28"/>
23+
24+
<!-- Required to to download files without a notification-->
25+
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION"/>
2326

2427
<application android:label="@string/app_name">
2528

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.os.Build;
99
import androidx.core.content.FileProvider;
1010
import android.util.SparseArray;
11+
import android.content.ActivityNotFoundException;
1112

1213
import com.facebook.react.bridge.ActivityEventListener;
1314
import com.facebook.react.bridge.Callback;
@@ -116,15 +117,14 @@ public void actionViewIntent(String path, String mime, @Nullable String chooserT
116117
Intent intent = new Intent(Intent.ACTION_VIEW);
117118
if (Build.VERSION.SDK_INT >= 24) {
118119
// Create the intent with data and type
119-
Intent intent = new Intent(Intent.ACTION_VIEW)
120-
.setDataAndType(uriForFile, mime);
120+
intent.setDataAndType(uriForFile, mime);
121121
if (chooserTitle != null) {
122122
intent = Intent.createChooser(intent, chooserTitle);
123123
}
124124

125125
// Set flag to give temporary permission to external app to use FileProvider
126126
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
127-
// All the activity to be opened outside of an activity
127+
// All the activity to be opened outside of an activity
128128
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
129129

130130
// Validate that the device can open the file
@@ -134,20 +134,22 @@ public void actionViewIntent(String path, String mime, @Nullable String chooserT
134134
}
135135

136136
} else {
137-
Intent intent = new Intent(Intent.ACTION_VIEW)
138-
.setDataAndType(Uri.parse("file://" + path), mime).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
137+
intent.setDataAndType(Uri.parse("file://" + path), mime).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
139138
if (chooserTitle != null) {
139+
intent = Intent.createChooser(intent, chooserTitle);
140+
}
140141

141-
PackageManager pm = getCurrentActivity().getPackageManager();
142-
if (intent.resolveActivity(pm) != null) {
143-
this.getReactApplicationContext().startActivity(intent);
144-
promise.resolve(true);
145-
} else {
146-
promise.reject("ENOAPP", "No app installed for " + mime);
142+
try {
143+
this.getReactApplicationContext().startActivity(intent);
144+
promise.resolve(true);
145+
} catch(ActivityNotFoundException ex) {
146+
promise.reject("ENOAPP", "No app installed for " + mime);
147+
}
147148
}
148149
ActionViewVisible = true;
149150

150151
final LifecycleEventListener listener = new LifecycleEventListener() {
152+
151153
@Override
152154
public void onHostResume() {
153155
if(ActionViewVisible)

0 commit comments

Comments
 (0)