A convenient way to update Android software version

1. Go to the server to request the software version number and download address

2. Get the app version number

public String getVersionName(Context context) {

    PackageInfo packageInfo = null;
    try {
         PackageManager packageManager = context.getPackageManager();
         packageInfo = packageManager.getPackageInfo(
         context.getPackageName(), 0);
        } catch (Exception e) {
          e.printStackTrace ();
        }
       return packageInfo.versionName;
}

2. Version number comparison, Dialog prompts the user whether to update

3. Update

         Intent intent = new Intent();
         intent.setAction("android.intent.action.VIEW");
         Uri apk_url = Uri.parse("http://file.jianguoduobao.com/JuBao/jubao.apk");
         intent.setData(apk_url );
         startActivity(intent);

In this way, you can automatically jump to the mobile application market to download, saving the download code.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325771561&siteId=291194637