国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

android實(shí)現(xiàn)程序自動(dòng)升級(jí)到安裝示例分享(下載android程序安裝包)

2020-04-11 11:56:13
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

復(fù)制代碼 代碼如下:

//程序下載升級(jí) zhouxiang
@JavascriptInterface
public void UpdateCAECP(final String path){
try{
AlertDialog.Builder builder = new Builder((Context)obj);
builder.setMessage(“檢測(cè)到有新版本發(fā)布,是否進(jìn)行下載升級(jí)?”);
builder.setTitle("程序更新提示");
builder.setPositiveButton("升級(jí)", new OnClickListener(){
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
m_pDialog = new ProgressDialog((Context)obj);
m_pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
m_pDialog.setTitle("程序升級(jí)中");
m_pDialog.setMessage("正在下載最新版的CAECP,請(qǐng)等候…");
m_pDialog.setIcon(R.drawable.ic_launcher);
m_pDialog.setProgress(100);
m_pDialog.setIndeterminate(false);
//設(shè)置ProgressDialog 是否可以按退回按鍵取消
m_pDialog.setCancelable(true);
m_pDialog.show();
new CAECP_DownloadFile(m_pDialog,(Context)obj).execute(path);
}
});
builder.setNegativeButton("取消", new OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
builder.create().show();
}catch(Exception e){
Alert("升級(jí)提示", e.getMessage(), "確認(rèn)");
}
}

復(fù)制代碼 代碼如下:

//zhouxiang 文件下載百分比 及 自動(dòng)安裝
public class CAECP_DownloadFile extends AsyncTask{
ProgressDialog m_pDialog=null;
String path="/sdcard/caecp/caecp.apk";
static String chattemp = "/sdcard/caecp/chat.caecp";
static String usertemp = "/sdcard/caecp/user.caecp";
Context obj;
CAECP_DownloadFile(ProgressDialog m_pDialog2,Context obj2){
m_pDialog=m_pDialog2;
obj=obj2;
}
@Override
protected String doInBackground(String… sUrl) {
try {
URL url = new URL(sUrl[0]);
URLConnection connection = url.openConnection();
connection.connect();
int fileLength = connection.getContentLength();
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(path);
byte data[] = new byte[1024];
long total = 0;
int count;
while ((count = input.read(data)) != -1) {
total += count;
m_pDialog.setProgress((int) (total * 100 / fileLength));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
DownCAECP_Ok();
} catch (Exception e) {
}
return null;
}
//下載CAECP文件完成,啟動(dòng)新線(xiàn)程,調(diào)用系統(tǒng)進(jìn)行安裝
public void DownCAECP_Ok(){
new Thread(){
public void run() {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setDataAndType(Uri.parse("file://" + path),"application/vnd.android.package-archive");
obj.startActivity(i);
}
}.start();
}

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 任丘市| 竹溪县| 南昌县| 会泽县| 大田县| 哈尔滨市| 迁西县| 甘谷县| 娄烦县| 商河县| 新竹市| 晋州市| 隆安县| 张掖市| 灵山县| 左贡县| 临城县| 行唐县| 眉山市| 长子县| 通江县| 浑源县| 荥经县| 敦化市| 北川| 晋江市| 漯河市| 勃利县| 舟山市| 嘉祥县| 鹿邑县| 监利县| 东港市| 灯塔市| 潍坊市| 股票| 固镇县| 泰兴市| 桂林市| 禹城市| 安乡县|