Procházet zdrojové kódy

Fix Download Manager bug when the file is not a multimedia #391

Ben Hsieh před 7 roky
rodič
revize
ed2732a47e

+ 14
- 2
android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java Zobrazit soubor

150
                 }
150
                 }
151
                 // set headers
151
                 // set headers
152
                 ReadableMapKeySetIterator it = headers.keySetIterator();
152
                 ReadableMapKeySetIterator it = headers.keySetIterator();
153
+                // #391 Add MIME type to the request
154
+                if(options.addAndroidDownloads.hasKey("mime")) {
155
+                    req.setMimeType(options.addAndroidDownloads.getString("mime"));
156
+                }
157
+
158
+                if(options.addAndroidDownloads.hasKey("mediaScannable") && options.addAndroidDownloads.hasKey("mediaScannable") == true ) {
159
+                    req.allowScanningByMediaScanner();
160
+                }
153
                 while (it.hasNextKey()) {
161
                 while (it.hasNextKey()) {
154
                     String key = it.nextKey();
162
                     String key = it.nextKey();
155
                     req.addRequestHeader(key, headers.getString(key));
163
                     req.addRequestHeader(key, headers.getString(key));
636
                         return;
644
                         return;
637
                     }
645
                     }
638
                     String contentUri = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
646
                     String contentUri = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
639
-                    if (contentUri != null) {
647
+                    if ( contentUri != null &&
648
+                            options.addAndroidDownloads.hasKey("mime") &&
649
+                            options.addAndroidDownloads.getString("mime").contains("image")) {
640
                         Uri uri = Uri.parse(contentUri);
650
                         Uri uri = Uri.parse(contentUri);
641
                         Cursor cursor = appCtx.getContentResolver().query(uri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
651
                         Cursor cursor = appCtx.getContentResolver().query(uri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
642
-                        // use default destination of DownloadManager
652
+
653
+                            // use default destination of DownloadManager
643
                         if (cursor != null) {
654
                         if (cursor != null) {
644
                             cursor.moveToFirst();
655
                             cursor.moveToFirst();
645
                             filePath = cursor.getString(0);
656
                             filePath = cursor.getString(0);
646
                         }
657
                         }
647
                     }
658
                     }
648
                 }
659
                 }
660
+
649
                 // When the file is not found in media content database, check if custom path exists
661
                 // When the file is not found in media content database, check if custom path exists
650
                 if (options.addAndroidDownloads.hasKey("path")) {
662
                 if (options.addAndroidDownloads.hasKey("path")) {
651
                     try {
663
                     try {