How to force update in Android application if new version is available?

后端 未结 6 502
小蘑菇
小蘑菇 2021-01-03 12:56

I am working on an application I want to give force update to app users if new version available on play store, the app should show a dialog message to user.

6条回答
  •  星月不相逢
    2021-01-03 13:45

    Store the versionCode of your app(which you have released on the playstore) on the server side. Hit the API every time user opens the app and get the versionCode. Compare the versionCode of the app user is currently using and the one you have stored on the server. Here is the code to get the versionCode of your app

    PackageManager manager = this.getPackageManager();
    PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
    String versionCode = info.versionCode;
    

    If the versionCode doesn't match(i.e versionCode from server > app's versionCode), prompt the user to update.

    P.S If you want to use this method, you have to update versionCode on your server every time you update the app on the playstore.

提交回复
热议问题