FinestWebView-Android icon indicating copy to clipboard operation
FinestWebView-Android copied to clipboard

Set Download Listener

Open taimur97 opened this issue 10 years ago • 13 comments

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 avatar Jan 19 '16 12:01 taimur97

@taimur97 Can you tell me how can I know whether the WebView is downloading something?

TheFinestArtist avatar Jan 26 '16 15:01 TheFinestArtist

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

    });

taimur97 avatar Feb 07 '16 15:02 taimur97

and is there anyway to add multiple window support?

taimur97 avatar Feb 07 '16 15:02 taimur97

+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.

fncapps avatar Feb 11 '16 22:02 fncapps

@taimur97 You mean multiple window such as Google Chrome Add new window? https://github.com/TheFinestArtist/FinestWebView-Android/issues/28

TheFinestArtist avatar Feb 14 '16 06:02 TheFinestArtist

Released 1.1.7 with onDownloadStart in WebViewListener.

public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength)

TheFinestArtist avatar Feb 14 '16 11:02 TheFinestArtist

Let me know if the listener doesn't work as you intended!

TheFinestArtist avatar Feb 14 '16 11:02 TheFinestArtist

Thanks man! ;)

fncapps avatar Feb 14 '16 12:02 fncapps

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 avatar Feb 14 '16 16:02 fncapps

@fncapps Sorry for late reply, I didn't notice that you asked me question! Let me check whether the method called.

TheFinestArtist avatar Mar 14 '16 02:03 TheFinestArtist

any update on this issue ?

samernady avatar Oct 11 '17 16:10 samernady

Me too! Any update for me it does not download at all even in FinestWebview itself!

Xenolion avatar Oct 23 '17 04:10 Xenolion

Please support with downloadlistener. I need it. Thanks!

iamgauravmishra avatar Feb 19 '18 18:02 iamgauravmishra