给Webview添加一个 wb.setDownloadListener(); 下载监听DownloadListener
实现如下
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype, long contentLength){
Context context = getContext();
if(context==null){
return;
}
wb.stopLoading();
Uri uri = Uri.parse(url);
if(Build.VERSION.SDK_INT>=9){//直接调用系统的下载管理应用下载。使用方法可以查找DownloadManager 相关
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Request request = new Request(uri);
request.setMimeType(mimetype);
request.setDescription("下载数据");
String path = uri.getPath();
int indexOf = path.lastIndexOf("/");
request.setDestinationUri(Uri.fromFile(new File(Environment.getExternalStorageState(),path.substring(indexOf+1, path.length()))));
request.setTitle("下载数