Set Download Listener
How can I set download listener? I want to listen for all the incoming downloads and start download in another activity by sending the url
@taimur97 Can you tell me how can I know whether the WebView is downloading something?
you just have to add the following code to listen for all incoming download
mWeb.getSettings().setJavaScriptEnabled(true); mWeb.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) {
// Start MainActivity for downloading
Intent i = new Intent();
i.setAction(MainActivity.INTENT_DOWNLOAD);
i.setDataAndType(Uri.parse(url), mimeType);
startActivity(i);
finish();
}
});
and is there anyway to add multiple window support?
+1! Really need this feature.
Maybe you can try just to provide a callback to onDownloadStart? Each dev could decide what they want to do with this method.
@taimur97 You mean multiple window such as Google Chrome Add new window? https://github.com/TheFinestArtist/FinestWebView-Android/issues/28
Released 1.1.7 with onDownloadStart in WebViewListener.
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength)
Let me know if the listener doesn't work as you intended!
Thanks man! ;)
Hi @TheFinestArtist , I've been looking into the listener but I'm not able to make it work. Here is what I have:
.setWebViewListener(new WebViewListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) {
super.onDownloadStart(url, userAgent, contentDisposition, mimeType, contentLength);
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
})
It throws me an error on startActivity saying "Cannot resolve method" probably because I can't tell him a context. But even if I write a Log.d("", "") inside there it never shows up.
Could you help me please? Thanks
@fncapps Sorry for late reply, I didn't notice that you asked me question! Let me check whether the method called.
any update on this issue ?
Me too! Any update for me it does not download at all even in FinestWebview itself!
Please support with downloadlistener. I need it. Thanks!