WebView mWebView =(WebView) findViewById(R.id.webView);
mWebView.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition,
String mimetype, long contentLength) {
if (contentDisposition == null
|| !contentDisposition.regionMatches(true, 0, "attachment", 0, 10)) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), mimetype);
ResolveInfo info = getPackageManager().resolveActivity(intent,
PackageManager.MATCH_DEFAULT_ONLY); if (info != null) {
ComponentName myName = getComponentName();
if (!myName.getPackageName().equals(info.activityInfo.packageName)
|| !myName.getClassName().equals(info.activityInfo.name)) {
try {
//使用ANDROID内置播放器
startActivity(intent);
return;
} catch (ActivityNotFoundException ex) {
}
}
} else {
//下载开始
//自定义下载
} }
} });
mWebView.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition,
String mimetype, long contentLength) {
if (contentDisposition == null
|| !contentDisposition.regionMatches(true, 0, "attachment", 0, 10)) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), mimetype);
ResolveInfo info = getPackageManager().resolveActivity(intent,
PackageManager.MATCH_DEFAULT_ONLY); if (info != null) {
ComponentName myName = getComponentName();
if (!myName.getPackageName().equals(info.activityInfo.packageName)
|| !myName.getClassName().equals(info.activityInfo.name)) {
try {
//使用ANDROID内置播放器
startActivity(intent);
return;
} catch (ActivityNotFoundException ex) {
}
}
} else {
//下载开始
//自定义下载
} }
} });
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货