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?
source share