Android版本检测 自动更新
2010-10-19 20:17:10 来源:WEB开发网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();
更多精彩
赞助商链接