80,471
社区成员




You need to override the shouldOverrideUrlLoading method of your 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);
}
}
}
... that you assign to your webview:
WebViewClient webViewClient = new MyWebViewClient();
webView.setWebViewClient(webViewClient);
Edit: also important that you add:
webView.getSettings().setAllowFileAccess(true);
to allow file downloads/streams such as mp4 files.