- WebView webView = (WebView) findViewById(R.id.webView);
- webView.setDownloadListener(new DownloadListener() {
-
- @Override
- public void onDownloadStart(String url, String userAgent,
- String contentDisposition, String mimetype, long contentLength) {
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.parse(url), mimetype);
- try {
- startActivity(intent);
- }catch (ActivityNotFoundException e){
- Log.w("YourLogTag", "Couldn't find activity to view mimetype: " + mimetype);
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- webView.setWebViewClient(new WebViewClient(){
-
- public boolean shouldOverrideUrlLoading(Webview view, String url){
- if(url.endsWith(".mp4") || url.endsWith("some other supported type")){
- Intent i = new Intent(Intent.ACTION_VIEW);
- i.setData(Uri.parse(url));
- startActivity(i);
- return true;
- } else {
- view.loadUrl(url);
- }
- return true;
- }});
WebView退出后flash视频播放器无法退出的问题 .
转自:http://blog.csdn.net/a345017062/article/details/6788502
- public void onPause() {
- super.onPause();
- webView.onPause();
- }
- public void onResume() {
- super.onResume();
- webView.onResume();
- }
把这两个加上就可以了。
另外,看到网上有提到有下面这种方式:
- webView.pauseTimers();
- webView.stopLoading();
- webView.loadData("<a></a>", "text/html", "utf-8");
这样直接就把视频停掉无法恢复了。