forked from mattermost/mattermost-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact-native-file-viewer+2.1.5.patch
44 lines (40 loc) · 1.75 KB
/
react-native-file-viewer+2.1.5.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
diff --git a/node_modules/react-native-file-viewer/android/src/main/java/com/vinzscam/reactnativefileviewer/RNFileViewerModule.java b/node_modules/react-native-file-viewer/android/src/main/java/com/vinzscam/reactnativefileviewer/RNFileViewerModule.java
index 93f7881..d81f609 100644
--- a/node_modules/react-native-file-viewer/android/src/main/java/com/vinzscam/reactnativefileviewer/RNFileViewerModule.java
+++ b/node_modules/react-native-file-viewer/android/src/main/java/com/vinzscam/reactnativefileviewer/RNFileViewerModule.java
@@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import androidx.core.content.FileProvider;
+import android.text.TextUtils;
import android.webkit.MimeTypeMap;
import com.facebook.react.bridge.ActivityEventListener;
@@ -41,6 +42,21 @@ public class RNFileViewerModule extends ReactContextBaseJavaModule {
reactContext.addActivityEventListener(mActivityEventListener);
}
+ private static String getExtension(String uri) {
+ if (uri == null) {
+ return null;
+ }
+
+ int dot = uri.lastIndexOf(".");
+ if (dot >= 0) {
+ // exclude the dot
+ return uri.substring(dot + 1);
+ } else {
+ // No extension.
+ return "";
+ }
+ }
+
@ReactMethod
public void open(String path, Integer currentId, ReadableMap options) {
Uri contentUri = null;
@@ -74,6 +90,9 @@ public class RNFileViewerModule extends ReactContextBaseJavaModule {
}
String extension = MimeTypeMap.getFileExtensionFromUrl(path).toLowerCase();
+ if (TextUtils.isEmpty(extension)) {
+ extension = getExtension(path);
+ }
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
Intent shareIntent = new Intent();