Android code for download file from webiew

How to make webview to download in android


I used ourSite variable to webview

Use following code for download file from webview


ourSite.setDownloadListener(new DownloadListener() {
       public void onDownloadStart(String url, String userAgent,
               String contentDisposition, String mimetype,
               long contentLength) {
         Intent downloadit = new Intent(Intent.ACTION_VIEW);
         downloadit.setData(Uri.parse(url));
         startActivity(downloadit);
       }
   });


Import header file
// for downloadlistener
import android.webkit.DownloadListener;
//for webview
import android.webkit.WebView;

Leave reply

Add your comments here

Back to Top