in doingBeauty View Android App, which involves the Android app download feature, the application itself is actually relatively simple, is through the WebView control call the corresponding Web page to display. Just beginning to think and ordinary file download implementation, only need a link, and then click on it can be implemented download, but put on the phone when the test, click Download Link a little reaction is not, in the normal page inside click is good, and click Other common links can be normal work. The original is because WebView default does not open the function of file download, if you want to implement the function of file download, need to set WebView Downloadlistener, by implementing their own downloadlistener to achieve the file download. Here's how:
1, set the WebView Downloadlistener:
Webview.setdownloadlistener (New Mywebviewdownloadlistener ());
2, the implementation of Mywebviewdownloadlistener this class, the specific can be as follows:
[Java]View Plaincopy
- Private class Mywebviewdownloadlistener implements Downloadlistener {
- @Override
- public void Ondownloadstart (string url, String useragent, String contentdisposition, String mimetype,
- long ContentLength) {
- Uri uri = uri.parse (URL);
- Intent Intent = new Intent (Intent.action_view, URI);
- StartActivity (Intent);
- }
- }
This is just a call to the system already built-in browser to download, not webview itself to do the file download, but this also basically satisfies our application scenario.
This article is from: Feng Libin's blog
Android webview for file download function