您的位置:首页 > 移动开发 > Android开发

android软件版本更新

2017-04-07 20:18 232 查看
版本更新

//获取版本号
version_code = UpdateBean.getData().getVersion_code();
//获取下载地址
download_url = UpdateBean.getData().getDownload_url();
Shared.writeString(getActivity(),"download_url",download_url);
doNewVersionUpdate();
/**
* 版本更新
*/
private void doNewVersionUpdate() {
//        int verCode = Integer.valueOf(GetPublicParams.getInstance().getVersionCode());
final AlertDialog dialog=new AlertDialog.Builder(getActivity()).create();
dialog.show();
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
Window window=dialog.getWindow();
window.setContentView(R.layout.update_version);
TextView tvUpdate= (TextView) window.findViewById(R.id.tv_update);
tvUpdate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
downLoadApk();
dialog.dismiss();
}
});
}

/**
* 下载APK
*/
private void downLoadApk() {
final ProgressDialog pd;    //进度条对话框
pd = new  ProgressDialog(getActivity());
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pd.setMessage("正在下载更新");
pd.show();
new Thread(){
@Override
public void run() {
try {
File file = DownLoadManager.getFileFromServer(download_url, pd);
sleep(3000);
installApk(file);
pd.dismiss(); //结束掉进度条对话框
} catch (Exception e) {
Message msg = new Message();
msg.what = 0x005;
handler.sendMessage(msg);
e.printStackTrace();
}
}}.start();
}

/**
* 安装APK
* @param file
*/
private void installApk(File file) {
Intent intent = new Intent();
//执行动作
intent.setAction(Intent.ACTION_VIEW);
//执行的数据类型
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: