@@ -93,48 +93,8 @@ class RNCWebViewManagerImpl(private val newArch: Boolean = false) {
9393 }
9494 webView.setDownloadListener(DownloadListener { url, userAgent, contentDisposition, mimetype, contentLength ->
9595 webView.setIgnoreErrFailedForThisURL(url)
96- val module = webView.reactApplicationContext.getNativeModule(RNCWebViewModule ::class .java) ? : return @DownloadListener
97- val request: DownloadManager .Request = try {
98- DownloadManager .Request (Uri .parse(url))
99- } catch (e: IllegalArgumentException ) {
100- Log .w(TAG , " Unsupported URI, aborting download" , e)
101- return @DownloadListener
102- }
103- var fileName = URLUtil .guessFileName(url, contentDisposition, mimetype)
104-
105- // Sanitize filename by replacing invalid characters with "_"
106- fileName = fileName.replace(invalidCharRegex, " _" )
107-
108- val downloadMessage = " Downloading $fileName "
109-
110- // Attempt to add cookie, if it exists
111- var urlObj: URL ? = null
112- try {
113- urlObj = URL (url)
114- val baseUrl = urlObj.protocol + " ://" + urlObj.host
115- val cookie = CookieManager .getInstance().getCookie(baseUrl)
116- request.addRequestHeader(" Cookie" , cookie)
117- } catch (e: MalformedURLException ) {
118- Log .w(TAG , " Error getting cookie for DownloadManager" , e)
119- }
120-
121- // Finish setting up request
122- request.addRequestHeader(" User-Agent" , userAgent)
123- request.setTitle(fileName)
124- request.setDescription(downloadMessage)
125- request.allowScanningByMediaScanner()
126- request.setNotificationVisibility(DownloadManager .Request .VISIBILITY_VISIBLE_NOTIFY_COMPLETED )
127- request.setDestinationInExternalPublicDir(Environment .DIRECTORY_DOWNLOADS , fileName)
128- module.setDownloadRequest(request)
129- if (module.grantFileDownloaderPermissions(
130- getDownloadingMessageOrDefault(),
131- getLackPermissionToDownloadMessageOrDefault()
132- )
133- ) {
134- module.downloadFile(
135- getDownloadingMessageOrDefault()
136- )
137- }
96+ android.widget.Toast .makeText(context, " File downloads are not supported" , android.widget.Toast .LENGTH_SHORT ).show();
97+ return @DownloadListener;
13898 })
13999 return RNCWebViewWrapper (context, webView)
140100 }
0 commit comments