浏览代码

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

Fixes #266. 
Now downloading works on Motorola Moto One with Android 9.
Marcin Ochyra 5 年前
父节点
当前提交
15d904f769
共有 1 个文件被更改,包括 1 次插入11 次删除
  1. 1
    11
      android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java

+ 1
- 11
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java 查看文件

@@ -7,7 +7,6 @@ import com.facebook.react.uimanager.UIManagerModule;
7 7
 
8 8
 import java.net.MalformedURLException;
9 9
 import java.net.URL;
10
-import java.net.URLDecoder;
11 10
 import java.util.LinkedList;
12 11
 import java.util.List;
13 12
 import java.util.regex.Pattern;
@@ -480,16 +479,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
480 479
 
481 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 483
         String downloadMessage = "Downloading " + fileName;
494 484
 
495 485
         //Attempt to add cookie, if it exists