将文件下载到 Android WebView(代码中没有下载事件或 HTTPClient) [英] Downloading a file to Android WebView (without the download event or HTTPClient in the code)
问题描述
这与其说是一个真正需要解决的问题,不如说是一个出于好奇的问题.我制作了一个包含 WebView 的 Android 应用程序.我使用了 should override URL 方法,这样点击的任何链接都会在 WebView 中打开.
This is more a question out of curiosity than a real problem that needs to be solved. I made an Android app which contains a WebView. I used the should override URL method so that any link clicked would be opened in the WebView.
后来我决定将文件从服务器下载到用户设备.不幸的是,我之前没有见过 setDownloadListener 方法.当用户现在单击链接时,不会启动下载.
Later I decided that a file would be downloaded from the server to the user device. Unfortunately I had not seen the setDownloadListener method before. When the user clicks a link now the download is not initiated.
据我所知,我需要使用正确的代码更新应用程序,即下载侦听器或 HttpClient,这没问题.
As far as I can tell I need to update the app with proper code i.e the download listener or a HttpClient, which is okay.
(冒着听起来像个白痴的风险)我想知道,是否有任何方法可以通过服务器的操作使 WebView 下载文件而无需更改代码?
(At the risk of sounding like an idiot) I am wondering, is there any way through an action from the server that I can make the WebView download a file without a code change?
我想该功能不在 WebView 中,这可能是 WebView 打开浏览器下载文件的原因.只是想也许我错过了一些让它工作的东西.我对此很陌生.
I guess that functionality is not in the WebView which is probably why the WebView opens a browser to download a file. Just thinking maybe I have missed something to make it work. I am pretty new to this.
推荐答案
我认为 webview 将只下载和呈现文本/html 内容和多部分.其余的将被定向到您看到的下载客户端.
I think webview will download and render only text/html contents and the multiparts. And the rest will be directed to a download client which you are seeing.
- Herojit
这篇关于将文件下载到 Android WebView(代码中没有下载事件或 HTTPClient)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!