WEB开发网
开发学院手机开发Android 开发 android自动更新软件版本 阅读

android自动更新软件版本

 2013-08-16 15:35:35 来源:WEB开发网   
核心提示:InputStream is = conn.getInputStream(); File file = new File(savePath); if (!file.exists()) { file.mkdir(); } File apkFile = new File(saveFileName); FileO
InputStream is = conn.getInputStream();
File file = new File(savePath);
if (!file.exists()) {
file.mkdir();
}
File apkFile = new File(saveFileName);
FileOutputStream out = new FileOutputStream(apkFile);
int count = 0;
int readnum = 0;
byte[] buffer = new byte[1024];
do {
readnum = is.read(buffer);
count += readnum;
progress = (int) (((float) count / length) * 100);
Log.e(TAG, "下载进度"+progress);
mhandler.sendEmptyMessage(DOWNLOAD_ING);
if (readnum <= 0) {
// 下载结束
mhandler.sendEmptyMessage(DOWNLOAD_OVER);
break;
}
out.write(buffer,0,readnum);
} while (!interceptFlag);
is.close();
out.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}
};
/*
* 安装下载的apk文件
*/
private void installApk() {
File file= new File(saveFileName);
if(!file.exists()){
return;
}
Intent intent= new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://"+file.toString()), "application/vnd.android.package-archive");
mContext.startActivity(intent);
}
}

上一页  1 2 3 

Tags:android 自动 更新

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接