Activity中:
mWebView.setDownloadListener(new MyDownload());
Class MyDownload implements DownloadListener{
public void onDownloadStart(String url ,String userAgent,
String contentDisposition,String mimetype,long contentLength){
//手动下载
new HttpThread(url).start();
//调用系统下载
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
}
}
下载的线程:
Class HttpThread extent Thread{
String url ;
public HttoThread(String url){
this.url = url;
}
public void run(){
URL httpUrl = new URL(url);
HttoCOnnection conn = httpUrl.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
InputStream in = conn.getInputStream();
File downloadFile,sdFile;
//判断内存卡是否存在
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
saFIle = new File(downloadFile,"text.apk");
}
//输入输出流处理
}
}