Prompt Android App User to Update App if current version <> market version

后端 未结 7 774
温柔的废话
温柔的废话 2020-12-01 02:46

Lets say my Android App version 0.1 is installed currently on the User\'s phone. Everytime they launch my App I want to check if there is a different version available in th

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 03:28

    Another option you can use, if you want to avoid having your backend server to store your current app version like it's suggested in the accepted answer, is to use Google Tag Manager (GTM).

    If you're already using the Google Analytics SDK, you have the GTM in it also.

    In GTM you can define a value in the container for your app that specifies your latest released version. For example:

    {
       "latestAppVersion": 14,
       ...
    }
    

    Then you can query that value when your app starts and show the user update dialog reminder if there's a newer version.

    Container container = TagManager.getInstance(context).openContainer(myContainerId);
    long latestVersionCode = container.getLong("latestAppVersion");
    
    // get currently running app version code
    PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    long versionCode = pInfo.versionCode;
    
    // check if update is needed
    if(versionCode < latestVersionCode) {
       // remind user to update his version
    }
    

提交回复
热议问题