Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix android Flag issue in android 9 and open file in Download directory in Android also #418

Merged
merged 2 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public void actionViewIntent(String path, String mime, final Promise promise) {

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

// Validate that the device can open the file
PackageManager pm = getCurrentActivity().getPackageManager();
Expand Down
23 changes: 18 additions & 5 deletions android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,25 @@ public static String getRealPathFromURI(final Context context, final Uri uri) {
}
// DownloadsProvider
else if (isDownloadsDocument(uri)) {
try {
final String id = DocumentsContract.getDocumentId(uri);
//Starting with Android O, this "id" is not necessarily a long (row number),
//but might also be a "raw:/some/file/path" URL
if (id != null && id.startsWith("raw:/")) {
Uri rawuri = Uri.parse(id);
String path = rawuri.getPath();
return path;
}
final Uri contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

return getDataColumn(context, contentUri, null, null);
return getDataColumn(context, contentUri, null, null);
}
catch (Exception ex) {
//something went wrong, but android should still be able to handle the original uri by returning null here (see readFile(...))
return null;
}

}
// MediaProvider
else if (isMediaDocument(uri)) {
Expand Down