Просмотр исходного кода

Merge pull request #418 from Crypho/Fix-Anroid-Issues-in-0-10-13

Fix android Flag issue in android 9 and open file in Download directory in Android also
Travis Nuttall 4 лет назад
Родитель
Сommit
f882654625
No account linked to committer's email address

+ 2
- 0
android/src/main/java/com/RNFetchBlob/RNFetchBlob.java Просмотреть файл

@@ -118,6 +118,8 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
118 118
 
119 119
                 // Set flag to give temporary permission to external app to use FileProvider
120 120
                 intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
121
+                 // All the activity to be opened outside of an activity
122
+                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
121 123
 
122 124
                 // Validate that the device can open the file
123 125
                 PackageManager pm = getCurrentActivity().getPackageManager();

+ 18
- 5
android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java Просмотреть файл

@@ -37,12 +37,25 @@ public class PathResolver {
37 37
             }
38 38
             // DownloadsProvider
39 39
             else if (isDownloadsDocument(uri)) {
40
+                try {
41
+                    final String id = DocumentsContract.getDocumentId(uri);
42
+                    //Starting with Android O, this "id" is not necessarily a long (row number),
43
+                    //but might also be a "raw:/some/file/path" URL
44
+                    if (id != null && id.startsWith("raw:/")) {
45
+                        Uri rawuri = Uri.parse(id);
46
+                        String path = rawuri.getPath();
47
+                        return path;
48
+                    }
49
+                    final Uri contentUri = ContentUris.withAppendedId(
50
+                            Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
40 51
 
41
-                final String id = DocumentsContract.getDocumentId(uri);
42
-                final Uri contentUri = ContentUris.withAppendedId(
43
-                        Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
44
-
45
-                return getDataColumn(context, contentUri, null, null);
52
+                    return getDataColumn(context, contentUri, null, null);
53
+                }
54
+                catch (Exception ex) {
55
+                    //something went wrong, but android should still be able to handle the original uri by returning null here (see readFile(...))
56
+                    return null;
57
+                }
58
+                
46 59
             }
47 60
             // MediaProvider
48 61
             else if (isMediaDocument(uri)) {