You need to override the method of shouldOverrideUrlLoadingyour webViewCient ...
final class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.endsWith(".mp4") {
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url));
view.getContext().startActivity(intent);
return true;
} else {
return super.shouldOverrideUrlLoading(view, url);
}
}
}
... which you assign to your webview:
WebViewClient webViewClient = new MyWebViewClient();
webView.setWebViewClient(webViewClient);
Edit: It is also important to add:
webView.getSettings().setAllowFileAccess(true);
to allow downloading files / streams such as mp4 files.
source
share