日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android新版本怎么下载安装,android 新版本下载 安装

發布時間:2024/1/8 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android新版本怎么下载安装,android 新版本下载 安装 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1 首先在程序啟動的時候 向服務器發送請求 服務器會返回??? String? newVerString="2|app.quannaojiaoyu.com......"

2 然后根據 “|”拆分為倆個list 元素?? 取第一個list 元素 和當前的版本號進行比較 如果此元素大于版本號 則發現新版本開始下載 url 為list的第二個元素? 下載完畢即可安裝

String newVerString = functions.getHttpResponse(

urlApi + "base.asp", "getVer");

System.out.println("newString--->"+newVerString);

Log.d("StartPage", "Check Server.");

if (newVerString != null)

{

ArrayList listVerStrings = functions.splitString(newVerString);

//得到當前版本號

int curVersion = functions.getAppVersionName(getApplicationContext());

Log.d("StartPage", listVerStrings.get(0));

// Check New Version

if (curVersion < Integer.parseInt(listVerStrings.get(0)))

{

Log.d("StartPage", "find new version.");

try

{

URL Url = new URL(listVerStrings.get(1));

URLConnection conn = Url.openConnection();

conn.connect();

InputStream is = conn.getInputStream();

int fileSize = conn.getContentLength();//獲取文件長度

Log.d("StartPage", "new version download start ("

+ String.valueOf(fileSize) + ")...");

msg = new Message();

msg.what = UPDATE_NEWVER;

msg.arg1 = fileSize;

handler.sendMessage(msg);

if (fileSize <= 0)return;

FileOutputStream FOS = new FileOutputStream(strSDPath

+ "/cawords.apk");

byte buf[] = new byte[1024];

int downLoadFilePosition = 0;

int numread;

while ((numread = is.read(buf)) != -1)

{

FOS.write(buf, 0, numread);

downLoadFilePosition += numread;

Log.d("StartPage", "new version downloading ("

+ String.valueOf(downLoadFilePosition)

+ ")...");

msg = new Message();

msg.what = UPDATE_DOWNLOAD;

msg.arg1 = downLoadFilePosition;

handler.sendMessage(msg);

}

Log.d("StartPage", "New Version Downloaded.");

Intent intent = new Intent();

// 安裝程序

intent.setDataAndType(

Uri.fromFile(new File(strSDPath

+ "/com.quannaojiaoyu.cadict.apk")),

"application/vnd.android.package-archive");

startActivity(intent);

Log.d("StartPage", "New Version Installed.");

finish();

System.exit(0);

} catch (Exception ex)

{

如何得到當前版本號:

public static int getAppVersionName(Context context) { ? int versionName = -1; ? try ? { ?? PackageManager pm = context.getPackageManager(); ?? PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); ?? versionName = pi.versionCode; ?? Log.d("versionName ", versionName +""); ? } catch (Exception e) ? { ?? Log.e("GET VER", "Exception", e); ? } ? return versionName; }

總結

以上是生活随笔為你收集整理的android新版本怎么下载安装,android 新版本下载 安装的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。