Android版本更新實(shí)例詳解
1、導(dǎo)入xutils的jar包

2、在AndroidManifest.xml中添加權(quán)限
3、選擇下載的路徑,和下載apk文件的網(wǎng)址
private String url=”http://www.oschina.NET/uploads/osc-Android-v2.6.4-release.apk”; private String sdPath = “/sdcard/” + System.currentTimeMillis() + “yuyin.apk”;
4、當(dāng)點(diǎn)擊按鈕的時(shí)候進(jìn)行下載
HttpUtils httpUtils=new HttpUtils(); //參數(shù)一:下載的路徑 參數(shù)二:下載到sdpath的路徑 參數(shù)三: httpUtils.download(url, sdPath, true, new RequestCallBack() { @Override public void onSuccess(ResponseInfo<File> arg0) { mBtn.setText("下載完成"); //路徑 String path = arg0.result.getPath(); File file = new File(path); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); startActivity(intent); } @Override public void onFailure(HttpException arg0, String arg1) { mBtn.setText("下載失敗"); } @Override public void onLoading(long total, long current, boolean isUploading) { // TODO Auto-generated method stub super.onLoading(total, current, isUploading); mBtn.setText("正在下載....."); } @Override public void onStart() { super.onStart(); mBtn.setText("開(kāi)始下載"); }});感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選