Browse Source

Add missing Android implementation

Ben Hsieh 7 years ago
parent
commit
d807f0f4af
2 changed files with 21 additions and 5 deletions
  1. 11
    3
      android.js
  2. 10
    2
      android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

+ 11
- 3
android.js View File

@@ -21,18 +21,26 @@ function actionViewIntent(path:string, mime:string = 'text/plain') {
21 21
   if(Platform.OS === 'android')
22 22
     return RNFetchBlob.actionViewIntent(path, mime)
23 23
   else
24
-    return Promise.reject('RNFetchBlob.actionViewIntent only supports Android.')
24
+    return Promise.reject('RNFetchBlob.android.actionViewIntent only supports Android.')
25 25
 }
26 26
 
27 27
 function getContentIntent(mime:string) {
28 28
   if(Platform.OS === 'android')
29 29
     return RNFetchBlob.getContentIntent(mime)
30 30
   else
31
-    return Promise.reject('RNFetchBlob.getContentIntent only supports Android.')
31
+    return Promise.reject('RNFetchBlob.android.getContentIntent only supports Android.')
32
+}
33
+
34
+function addCompleteDownload(config) {
35
+  if(Platform.OS === 'android')
36
+    return RNFetchBlob.addCompleteDownload(config)
37
+  else
38
+    return Promise.reject('RNFetchBlob.android.addCompleteDownload only supports Android.')
32 39
 }
33 40
 
34 41
 
35 42
 export default {
36 43
   actionViewIntent,
37
-  getContentIntent
44
+  getContentIntent,
45
+  addCompleteDownload
38 46
 }

+ 10
- 2
android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java View File

@@ -882,13 +882,21 @@ public class RNFetchBlobFS {
882 882
         return false;
883 883
     }
884 884
 
885
+    /**
886
+     * Normalize the path, remove URI scheme (xxx://) so that we can handle it.
887
+     * @param path URI string.
888
+     * @return Normalized string
889
+     */
885 890
     static String normalizePath(String path) {
886 891
         if(path == null)
887 892
             return null;
888
-        Uri uri = Uri.parse(path);
889
-        if(uri.getScheme() == null) {
893
+        if(!path.matches("\\w+\\:.*"))
890 894
             return path;
895
+        if(path.startsWith("file://")) {
896
+            return path.replace("file://", "");
891 897
         }
898
+
899
+        Uri uri = Uri.parse(path);
892 900
         if(path.startsWith(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET)) {
893 901
             return path;
894 902
         }