From 029cf17e1d6985243469d0a928f314a8243d84b2 Mon Sep 17 00:00:00 2001 From: Christian Guy Date: Fri, 16 Oct 2020 10:58:34 +0200 Subject: [PATCH] Fix actionViewIntent for Android <= 6 --- .../java/com/RNFetchBlob/RNFetchBlob.java | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java b/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java index 602d51d33..e64e90b5a 100644 --- a/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java +++ b/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java @@ -111,28 +111,23 @@ public void actionViewIntent(String path, String mime, final Promise promise) { Uri uriForFile = FileProvider.getUriForFile(getCurrentActivity(), this.getReactApplicationContext().getPackageName() + ".provider", new File(path)); - if (Build.VERSION.SDK_INT >= 24) { - // Create the intent with data and type - Intent intent = new Intent(Intent.ACTION_VIEW) - .setDataAndType(uriForFile, mime); - - // 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(); - if (intent.resolveActivity(pm) != null) { - this.getReactApplicationContext().startActivity(intent); - } - - } else { - Intent intent = new Intent(Intent.ACTION_VIEW) - .setDataAndType(Uri.parse("file://" + path), mime).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - + // Create the intent with data and type + Intent intent = new Intent(Intent.ACTION_VIEW) + .setDataAndType(uriForFile, mime); + + // 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(); + if (intent.resolveActivity(pm) != null) { this.getReactApplicationContext().startActivity(intent); + } else { + promise.reject("EUNSPECIFIED", "Cannot open the URL."); } + ActionViewVisible = true; final LifecycleEventListener listener = new LifecycleEventListener() {