安卓:我如何从一个动态的URL网页视图下载文件 [英] Android: How do I download a file from a dynamic url webview
问题描述
在我的应用我使用的是web视图通过导航到一个网站,会自动使用JavaScript,然后提交,以获得一个链接到一个CSV文件导出在Web表格。
链接如下:XYZ.com/TEST/index/getexport?id=130。
In my app I am using a webview to navigate through to a site, automatically fill in a web form using javascript then submit to obtain a link to a CSV export file. The link looks like this: XYZ.com/TEST/index/getexport?id=130.
我想将文件下载此URL指向,然后完成时,它读入一个本地数据库,但我无法下载链接的文件。
I'd like to download the file this URL points to, then when complete read it into a local database but I'm having trouble downloading the linked file.
如果我只是尝试在web视图中打开URL我从网页告诉我,没有这样的文件中存在一个错误。
If I simply try to open the URL in webview I get an error from the webpage telling me no such file exists.
如果我使用了下载管理器下载它自己,源$ C $ C下载为HTML文件,而不是相关的.csv文件。
If I use the Download Manager to download it myself, the source code is downloaded as an html file, not the associated .csv file.
我可以用一个ACTION_VIEW意图和浏览器(Chrome)打开URL下载正确的文件,但这样一来,我没有下载完成时通知。
I can open the url with an ACTION_VIEW intent and a browser (chrome) downloads the correct file, but this way I have no notification of when the download completes.
如何下载我的.CSV文件中的任何想法?
Any ideas of how to download my .CSV file?
推荐答案
要从网页视图使用下载文件这样的:
To download a file from webview use this :
mWebView.setDownloadListener(new DownloadListener(){
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength){
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
希望这有助于。
这篇关于安卓:我如何从一个动态的URL网页视图下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!