Skip to content

Commit 28f4a54

Browse files
authored
Merge pull request #685 from Chris-Guy/master
[Android] Fix actionViewIntent for SDK < 24
2 parents 4a2f8c4 + 029cf17 commit 28f4a54

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

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

+15-20
Original file line numberDiff line numberDiff line change
@@ -111,28 +111,23 @@ public void actionViewIntent(String path, String mime, final Promise promise) {
111111
Uri uriForFile = FileProvider.getUriForFile(getCurrentActivity(),
112112
this.getReactApplicationContext().getPackageName() + ".provider", new File(path));
113113

114-
if (Build.VERSION.SDK_INT >= 24) {
115-
// Create the intent with data and type
116-
Intent intent = new Intent(Intent.ACTION_VIEW)
117-
.setDataAndType(uriForFile, mime);
118-
119-
// Set flag to give temporary permission to external app to use FileProvider
120-
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
121-
// All the activity to be opened outside of an activity
122-
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
123-
124-
// Validate that the device can open the file
125-
PackageManager pm = getCurrentActivity().getPackageManager();
126-
if (intent.resolveActivity(pm) != null) {
127-
this.getReactApplicationContext().startActivity(intent);
128-
}
129-
130-
} else {
131-
Intent intent = new Intent(Intent.ACTION_VIEW)
132-
.setDataAndType(Uri.parse("file://" + path), mime).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
133-
114+
// Create the intent with data and type
115+
Intent intent = new Intent(Intent.ACTION_VIEW)
116+
.setDataAndType(uriForFile, mime);
117+
118+
// Set flag to give temporary permission to external app to use FileProvider
119+
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
120+
// All the activity to be opened outside of an activity
121+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
122+
123+
// Validate that the device can open the file
124+
PackageManager pm = getCurrentActivity().getPackageManager();
125+
if (intent.resolveActivity(pm) != null) {
134126
this.getReactApplicationContext().startActivity(intent);
127+
} else {
128+
promise.reject("EUNSPECIFIED", "Cannot open the URL.");
135129
}
130+
136131
ActionViewVisible = true;
137132

138133
final LifecycleEventListener listener = new LifecycleEventListener() {

0 commit comments

Comments
 (0)