From 15d904f769935652f24e9ec3c6f0ebd0da17d6c0 Mon Sep 17 00:00:00 2001 From: Marcin Ochyra Date: Tue, 29 Jan 2019 10:05:25 +0100 Subject: [PATCH] fix(android): Fix Download on android P (#273) Fixes #266. Now downloading works on Motorola Moto One with Android 9. --- .../webview/RNCWebViewManager.java | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java index 663416c..d1b050d 100644 --- a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java +++ b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java @@ -7,7 +7,6 @@ import com.facebook.react.uimanager.UIManagerModule; import java.net.MalformedURLException; import java.net.URL; -import java.net.URLDecoder; import java.util.LinkedList; import java.util.List; import java.util.regex.Pattern; @@ -480,16 +479,7 @@ public class RNCWebViewManager extends SimpleViewManager { DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); - //Try to extract filename from contentDisposition, otherwise guess using URLUtil - String fileName = ""; - try { - fileName = contentDisposition.replaceFirst("(?i)^.*filename=\"?([^\"]+)\"?.*$", "$1"); - fileName = URLDecoder.decode(fileName, "UTF-8"); - } catch (Exception e) { - System.out.println("Error extracting filename from contentDisposition: " + e); - System.out.println("Falling back to URLUtil.guessFileName"); - fileName = URLUtil.guessFileName(url,contentDisposition,mimetype); - } + String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype); String downloadMessage = "Downloading " + fileName; //Attempt to add cookie, if it exists