Skip to content

Commit f882654

Browse files
authored
Merge pull request joltup#418 from Crypho/Fix-Anroid-Issues-in-0-10-13
Fix android Flag issue in android 9 and open file in Download directory in Android also
2 parents 085db09 + 95207a9 commit f882654

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

Diff for: android/src/main/java/com/RNFetchBlob/RNFetchBlob.java

+2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ public void actionViewIntent(String path, String mime, final Promise promise) {
118118

119119
// Set flag to give temporary permission to external app to use FileProvider
120120
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);
121123

122124
// Validate that the device can open the file
123125
PackageManager pm = getCurrentActivity().getPackageManager();

Diff for: android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java

+18-5
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,25 @@ public static String getRealPathFromURI(final Context context, final Uri uri) {
3737
}
3838
// DownloadsProvider
3939
else if (isDownloadsDocument(uri)) {
40+
try {
41+
final String id = DocumentsContract.getDocumentId(uri);
42+
//Starting with Android O, this "id" is not necessarily a long (row number),
43+
//but might also be a "raw:/some/file/path" URL
44+
if (id != null && id.startsWith("raw:/")) {
45+
Uri rawuri = Uri.parse(id);
46+
String path = rawuri.getPath();
47+
return path;
48+
}
49+
final Uri contentUri = ContentUris.withAppendedId(
50+
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
4051

41-
final String id = DocumentsContract.getDocumentId(uri);
42-
final Uri contentUri = ContentUris.withAppendedId(
43-
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
44-
45-
return getDataColumn(context, contentUri, null, null);
52+
return getDataColumn(context, contentUri, null, null);
53+
}
54+
catch (Exception ex) {
55+
//something went wrong, but android should still be able to handle the original uri by returning null here (see readFile(...))
56+
return null;
57+
}
58+
4659
}
4760
// MediaProvider
4861
else if (isMediaDocument(uri)) {

0 commit comments

Comments
 (0)