DownloadListener.onDownloadStart () never called

In my attempts to create a WebView that plays YouTube videos through HTML5 (and not through Flash), I tried to implement this article verbatim, right inside my onCreate () activity:

WebView webView = (WebView) findViewById(R.id.embeddedWebView); webView.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long size) { Log.v("TAG", "url: " + url + ", mimeType: " + mimeType); Intent viewIntent = new Intent(Intent.ACTION_VIEW); viewIntent.setDataAndType(Uri.parse(url), mimeType); try { startActivity(viewIntent); } catch (ActivityNotFoundException ex) { Log.w("YourLogTag", "Couldn't find activity to view mimetype: " + mimeType); } } }); 

For some reason it was not called, therefore, noticing that nowhere in my code I specify "implements DownloadListener", I re-implemented it as a separate class, which was defined as

 public class MyDownloadListener implements DownloadListener 

and implements onDownloadStart () as above (passing the activity as a parameter so that it can call startActivity (). Then in onCreate () I just do:

 mDownloadListener = new MyDownloadListener(this); mWebView.setDownloadListener(mDownloadListener); 

I tried YouTube again on http://broken-links.com/tests/video/ and I still don’t see any trace in LogCat that onDownloadStart () is ever called.

What do I need to do to call it? What am I missing?

+4
source share
1 answer

setDownloadListener sets the listener when the WebView does not consider that the content can be handled by the rendering engine.

Register the interface that will be used when the content cannot be processed by the rendering engine and should be downloaded. This will replace the current handler.

Webview uses the WebKit rendering engine, and I believe that it can (or thinks it can) handle html5 so that the listener is not called.

+6
source

All Articles