Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download file inside WebView

I have a webview in my Android Application. When user goes to webview and click a link to download a file nothing happens.

URL = "my url"; mWebView = (WebView) findViewById(R.id.webview); mWebView.setWebViewClient(new HelloWebViewClient()); mWebView.getSettings().setDefaultZoom(ZoomDensity.FAR); mWebView.loadUrl(URL); Log.v("TheURL", URL); 

How to enable download inside a webview? If I disable webview and enable the intent to load the URL on browser from application then download works seamlessly.

String url = "my url"; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); 

Can someone help me out here? The page loads without issue but the link to a image file in the HTML page is not working...

like image 819
Jay Mayu Avatar asked Apr 09 '12 04:04

Jay Mayu


People also ask

Can we download file in WebView?

Application Xamarin Forms Android. The application has a WebView element that displays different sites. On these sites, it is possible to download files. But the file cannot be downloaded via WebView.

How to download files in Android WebView?

The download manager is a service that can be used to handle downloads. Set the download URL and when the Download manager is invoked it will download the file in the background. It needs permission to write into storage and permission to access the Internet.

How do I download files on Android?

Go to the webpage where you want to download a file. Touch and hold what you want to download, then tap Download link or Download image. To see all the files you've downloaded to your device, open the Downloads app.


1 Answers

Have you tried?

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);     } }); 

Example Link: Webview File Download - Thanks @c49

like image 178
user370305 Avatar answered Sep 19 '22 11:09

user370305