WEB开发网
开发学院手机开发Android 开发 Android 实现版本检测\自动更新 阅读

Android 实现版本检测\自动更新

 2010-09-10 00:31:00 来源:WEB开发网   
核心提示:return;}if (true) {// Check version.showUpdateDialog();}}public static boolean isNetworkAvailable(Context ctx) {try {ConnectivityManager cm = (ConnectivityManag

return;

}

if (true) {// Check version.

showUpdateDialog();

}

}

public static boolean isNetworkAvailable(Context ctx) {

try {

ConnectivityManager cm = (ConnectivityManager) ctx

.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo info = cm.getActiveNetworkInfo();

return (info != null && info.isConnected());

} catch (Exception e) {

e.printStackTrace();

return false;

}

}

public void showUpdateDialog() {

@SuppressWarnings("unused")

AlertDialog alert = new AlertDialog.Builder(this.activity)

.setTitle("Title")

.setIcon(R.drawable.icon)

.setMessage("Update or not?")

.setPositiveButton("Update",

new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog,

int which) {

downloadTheFile(strURL);

showWaitDialog();

}

})

.setNegativeButton("Cancel",

new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog,

int which) {

dialog.cancel();

}

}).show();

}

public void showWaitDialog() {

dialog = new ProgressDialog(activity);

dialog.setMessage("Waitting for update...");

dialog.setIndeterminate(true);

dialog.setCancelable(true);

dialog.show();

}

public void getCurrentVersion() {

try {

PackageInfo info = activity.getPackageManager().getPackageInfo(

activity.getPackageName(), 0);

this.versionCode = info.versionCode;

this.versionName = info.versionName;

} catch (NameNotFoundException e) {

e.printStackTrace();

上一页  1 2 3 4  下一页

Tags:Android 实现

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