android實現(xiàn)程序自動升級到安裝示例分享(下載android程序安裝包)
更新時間:2014年01月19日 15:26:06 作者:
這篇文章主要介紹了android實現(xiàn)下載android程序安裝包自動升級的示例,大家參考使用吧
復制代碼 代碼如下:
//程序下載升級 zhouxiang
@JavascriptInterface
public void UpdateCAECP(final String path){
try{
AlertDialog.Builder builder = new Builder((Context)obj);
builder.setMessage(“檢測到有新版本發(fā)布,是否進行下載升級?”);
builder.setTitle("程序更新提示");
builder.setPositiveButton("升級", 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("程序升級中");
m_pDialog.setMessage("正在下載最新版的CAECP,請等候…");
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("升級提示", e.getMessage(), "確認");
}
}
復制代碼 代碼如下:
//zhouxiang 文件下載百分比 及 自動安裝
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文件完成,啟動新線程,調(diào)用系統(tǒng)進行安裝
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();
}
相關(guān)文章
Android 自定義 View 中使用 Spannable的實例詳解
這篇文章主要介紹了Android 自定義 View 中使用 Spannable的相關(guān)知識,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-05-05Android實現(xiàn)Service下載文件,Notification顯示下載進度的示例
本篇文章主要介紹了Android實現(xiàn)Service下載文件,Notification顯示下載進度,具有一定的參考價值,有興趣的可以了解一下。2017-01-01Android訪問php取回json數(shù)據(jù)實例
Android訪問php取回json數(shù)據(jù),實現(xiàn)代碼如下,遇到訪問網(wǎng)絡(luò)的權(quán)限不足在AndroidManifest.xml中,需要進行如下配置2013-06-06Flutter使用AnimatedSwitcher實現(xiàn)場景切換動畫
在應用中,我們經(jīng)常會遇到切換組件的場景。本文將利用Flutter中提供的AnimatedSwitcher這一動畫組件來實現(xiàn)頁面內(nèi)的場景切換,需要的可參考一下2022-03-03Android Studio連接SQLite數(shù)據(jù)庫的登錄注冊實現(xiàn)
這篇文章主要介紹了Android Studio連接SQLite數(shù)據(jù)庫的登錄注冊實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-06-06Android實現(xiàn)快遞單號查詢快遞狀態(tài)信息
這篇文章主要為大家詳細介紹了Android實現(xiàn)快遞單號查詢快遞狀態(tài)信息,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-05-05