Browse Source

fix(android): Fix Download on android P (#273)

Fixes #266. 
Now downloading works on Motorola Moto One with Android 9.
Marcin Ochyra 5 years ago
parent
commit
15d904f769

+ 1
- 11
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java View File

7
 
7
 
8
 import java.net.MalformedURLException;
8
 import java.net.MalformedURLException;
9
 import java.net.URL;
9
 import java.net.URL;
10
-import java.net.URLDecoder;
11
 import java.util.LinkedList;
10
 import java.util.LinkedList;
12
 import java.util.List;
11
 import java.util.List;
13
 import java.util.regex.Pattern;
12
 import java.util.regex.Pattern;
480
 
479
 
481
         DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
480
         DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
482
 
481
 
483
-        //Try to extract filename from contentDisposition, otherwise guess using URLUtil
484
-        String fileName = "";
485
-        try {
486
-          fileName = contentDisposition.replaceFirst("(?i)^.*filename=\"?([^\"]+)\"?.*$", "$1");
487
-          fileName = URLDecoder.decode(fileName, "UTF-8");
488
-        } catch (Exception e) {
489
-          System.out.println("Error extracting filename from contentDisposition: " + e);
490
-          System.out.println("Falling back to URLUtil.guessFileName");
491
-          fileName = URLUtil.guessFileName(url,contentDisposition,mimetype);
492
-        }
482
+        String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype);
493
         String downloadMessage = "Downloading " + fileName;
483
         String downloadMessage = "Downloading " + fileName;
494
 
484
 
495
         //Attempt to add cookie, if it exists
485
         //Attempt to add cookie, if it exists