android webview处理下载内容
url = "http://m.mumayi.com/"; WebView = (WebView) findViewById(R.id.webView1); WebView.getSettings().setJavaScriptEnabled(true); WebView.requestFocus(); WebView.getSettings().setDefaultTextEncodingName("utf-8"); WebView.loadUrl(url); // 设置web视图客户端 WebView.setDownloadListener(new MyWebViewDownLoadListener( DownLoadActivity.this)); WebView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { WebView.loadUrl(url); return true; } });
MyWebViewDownLoadListener:
public class MyWebViewDownLoadListener implements DownloadListener { private Context context; public MyWebViewDownLoadListener(Context context) { this.context = context; } @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Uri uri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, uri); context.startActivity(intent); } }