Android programmatically update application when a new version is available

前端 未结 9 1960
别那么骄傲
别那么骄傲 2020-12-01 08:45

Within my application, I want to check if there is any updated version of my application is in the app store. If there is any, then have to inform the user through an alert

9条回答
  •  既然无缘
    2020-12-01 09:19

     private void checkForUpdate() {
            PackageInfo packageInfo = null;
            try {      packageInfo=getPackageManager().getPackageInfo(DashboardActivity.this.getPackageName(), 0);
                int curVersionCode = packageInfo.versionCode
                if (curVersionCode > 1) {  // instead of one use value get from server for the new update.
                    showUpdateDialog();
                }
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
        }
    

提交回复
热议问题