Created
November 10, 2021 17:41
-
-
Save Aure77/5b0f75aee85fa897d6a3469146a197df to your computer and use it in GitHub Desktop.
react-native-blob-util actionViewIntent fix for Android 11+ devices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/node_modules/react-native-blob-util/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtil.java b/node_modules/react-native-blob-util/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtil.java | |
index 0e1dffd..0eb5bdf 100644 | |
--- a/node_modules/react-native-blob-util/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtil.java | |
+++ b/node_modules/react-native-blob-util/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtil.java | |
@@ -118,36 +118,26 @@ public class ReactNativeBlobUtil extends ReactContextBaseJavaModule { | |
this.getReactApplicationContext().getPackageName() + ".provider", new File(path)); | |
Intent intent = new Intent(Intent.ACTION_VIEW); | |
- if (Build.VERSION.SDK_INT >= 24) { | |
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | |
// Create the intent with data and type | |
intent.setDataAndType(uriForFile, mime); | |
- if (chooserTitle != null) { | |
- intent = Intent.createChooser(intent, chooserTitle); | |
- } | |
// 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.setDataAndType(Uri.parse("file://" + path), mime).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
- if (chooserTitle != null) { | |
- intent = Intent.createChooser(intent, chooserTitle); | |
- } | |
+ } | |
- try { | |
- this.getReactApplicationContext().startActivity(intent); | |
- promise.resolve(true); | |
- } catch (ActivityNotFoundException ex) { | |
- promise.reject("ENOAPP", "No app installed for " + mime); | |
- } | |
+ if (chooserTitle != null) { | |
+ intent = Intent.createChooser(intent, chooserTitle); | |
+ } | |
+ try { | |
+ this.getReactApplicationContext().startActivity(intent); | |
+ promise.resolve(true); | |
+ } catch (ActivityNotFoundException ex) { | |
+ promise.reject("ENOAPP", "No app installed for " + mime); | |
} | |
ActionViewVisible = true; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment