TheFinestArtist / FinestWebView-Android

Beautiful and customizable Android Activity that shows web pages within an app.
https://finestwebview.web.app
2.32k stars 531 forks source link

Set Download Listener #21

Open taimur97 opened 8 years ago

taimur97 commented 8 years ago

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

TheFinestArtist commented 8 years ago

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

taimur97 commented 8 years ago

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 commented 8 years ago

and is there anyway to add multiple window support?

fncapps commented 8 years ago

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

TheFinestArtist commented 8 years ago

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

TheFinestArtist commented 8 years ago

Released 1.1.7 with onDownloadStart in WebViewListener.

public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength)
TheFinestArtist commented 8 years ago

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

fncapps commented 8 years ago

Thanks man! ;)

fncapps commented 8 years ago

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

TheFinestArtist commented 8 years ago

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

samernady commented 7 years ago

any update on this issue ?

Xenolion commented 7 years ago

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

iamgauravmishra commented 6 years ago

Please support with downloadlistener. I need it. Thanks!