How to notify users about an Android app update?

前端 未结 17 690
眼角桃花
眼角桃花 2020-11-28 23:30

I\'ve built an Android app which is now on Play Market. From time to time, I make updates to it, and I\'d like to let users know that a new version is available.

How

相关标签:
17条回答
  • 2020-11-29 00:18

    Don't know if you want to walk extra miles. You can try out google appengine, which serve version number for your app and let you android app check the appengine to see if there is a new version when the application is launched. That way, it does not matter if your app is in google play market nor amazon app store nor if it is installed on the phone without those two via sideloading. It is not very hard to setup appengine just for serving your application version in json. Replace "Hello World" string with your app version name ...

    0 讨论(0)
  • 2020-11-29 00:19

    Generally when you upload a new application to Google play most users get a notification about an update, some will have the app automatically downloaded to their device, depending on the settings they have. If you seriously want to make a notification from your app to ask them to update (so that everyone gets the notification, whatever their Google play settings are, then you will have to make a web service which returns the number of the newest version. You can then compare that inside your app and post a notification. You could use Google App Engine ( https://developers.google.com/appengine/) because that works with eclipse and java, which you probably already have. I would not recommend this approach as it creates a lot of work for you to provide something that most users have already got.

    0 讨论(0)
  • 2020-11-29 00:21

    Found a nice solution for your problem: Let´s say you want to check for version updates manually on app start and notify your users for the new Update.

    Step 1: Download android-market-api (not the .jar file, the full project!)

    Step 2: After importing it to eclipse, write in your activity the following code:

    MarketService ms = new MarketService(activity);
    ms.level(MarketService.REVISION).checkVersion();
    

    now, we need to modify MarketService.java, because it seems to be broken.

    Step 3: rewrite callback method and add the following methods

    protected void callback(String url, JSONObject jo, AjaxStatus status){      
            if(jo == null) return;
            String googlePlayversion = jo.optString("version", "0");
            String smartphone_version = "";
    
            PackageInfo pInfo;
            try {
                pInfo = act.getPackageManager().getPackageInfo(act.getPackageName(), 0);
                smartphone_version = pInfo.versionName;
            } catch (NameNotFoundException e) {}
            boolean new_version_avaible = compare(smartphone_version, googlePlayversion);
            if(new_version_avaible){
                showUpdateDialog(jo);
            }
        }
    
        private static boolean compare(String v1, String v2) {
            String s1 = normalisedVersion(v1);
            String s2 = normalisedVersion(v2);
            int cmp = s1.compareTo(s2);
            String cmpStr = cmp < 0 ? "<" : cmp > 0 ? ">" : "==";
            System.out.printf("result: "+"'%s' %s '%s'%n", v1, cmpStr, v2);
            if(cmpStr.contains("<")){
                return true;
            }
            if(cmpStr.contains(">")||cmpStr.contains("==")){
                return false;
            }
            return false;
        }
    
        public static String normalisedVersion(String version) {
            return normalisedVersion(version, ".", 4);
        }
    
        public static String normalisedVersion(String version, String sep, int maxWidth) {
            String[] split = Pattern.compile(sep, Pattern.LITERAL).split(version);
            StringBuilder sb = new StringBuilder();
            for (String s : split) {
                sb.append(String.format("%" + maxWidth + 's', s));
            }
            return sb.toString();
        }
    

    If you want to test it, modify googlePlayversion string to a higher version than your local one.

    The source comparison method I used is from How do you compare two version Strings in Java?

    0 讨论(0)
  • 2020-11-29 00:23

    i think this is too late but it can be help some one

    public enum AppVersionUpgradeNotifier {
    INSTANCE;
    
    private static final String TAG = "AppVersionUpdateManager";
    
    private static final String PREFERENCES_APP_VERSION = "pref_app_version_upgrade";
    private static final String KEY_LAST_VERSION = "last_version";
    
    private SharedPreferences sharedPreferences;
    private VersionUpdateListener versionUpdateListener;
    private boolean isInitialized;
    
    public static synchronized void init(Context context, VersionUpdateListener versionUpdateListener) {
        if (context == null || versionUpdateListener == null) {
            throw new IllegalArgumentException(TAG + " : Context or VersionUpdateListener is null");
        }
    
        if (!INSTANCE.isInitialized) {
            INSTANCE.initInternal(context, versionUpdateListener);
        } else {
            Log.w(TAG, "Init called twice, ignoring...");
        }
    }
    
    private void initInternal(Context context, VersionUpdateListener versionUpdateListener) {
        this.sharedPreferences = context.getSharedPreferences(PREFERENCES_APP_VERSION, Context.MODE_PRIVATE);
        this.versionUpdateListener = versionUpdateListener;
        this.isInitialized = true;
        checkVersionUpdate();
    }
    
    private void checkVersionUpdate() {
        int lastVersion = getLastVersion();
        int currentVersion = getCurrentVersion();
    
        if (lastVersion < currentVersion) {
            if (versionUpdateListener.onVersionUpdate(currentVersion, lastVersion)) {
                upgradeLastVersionToCurrent();
            }
        }
    }
    
    private int getLastVersion() {
        return sharedPreferences.getInt(KEY_LAST_VERSION, 0);
    }
    
    private int getCurrentVersion() {
        return BuildConfig.VERSION_CODE;
    }
    
    public void upgradeLastVersionToCurrent() {
        sharedPreferences.edit().putInt(KEY_LAST_VERSION, getCurrentVersion()).apply();
    }
    
    public interface VersionUpdateListener {
        boolean onVersionUpdate(int newVersion, int oldVersion);
    }
    

    }

    use it on

    public class MyApplication extends Application implements AppVersionUpgradeNotifier.VersionUpdateListener {
    
    @Override
    public void onCreate() {
        super.onCreate();
    
        AppVersionUpgradeNotifier.init(this,this);
    }
    
    @Override
    public boolean onVersionUpdate(int newVersion, int oldVersion) {
        //do what you want
    
        return true;
    }
    

    }

    0 讨论(0)
  • 2020-11-29 00:24

    It is up to each phone owner if she wants to be notified on new versions by google play, and it's up to each phone's manufacturer if this is to be enabled by default.

    If you however are in a situation where you "require" the user to update to the new version to be compatible with some form of protocol or you have a similar similar use case where you have a server component somewhere, you might want to notify the user of a potential version conflict in the UI based on information about what is the latest version.

    This information can be grabbed directrly from google play, however as @Yahel pointed out in this question google play is a closed system with no official API, and you might need to rely on unpredictable undocumented API. There is an unofficial API library here.

    This leaves only one option, which is to keep this information on your own server. If you allready have a serverside this might be trivial. Simply put the latest version in an XML file and retreive that at regular intervals from your code. If the version code is outdated, trigger the notification in your UI. Here is an example implementation for doing that.

    I hope this was helpful :-)

    0 讨论(0)
  • 2020-11-29 00:24

    Google Play will notify your users that the app has an update via the notification bar.

    If you set up a notification system yourself, the likely result would be that, although the user is notified of an update sooner, when he/she goes to Google Play to install the update it will not yet be available. This is because there is a lag from the time you "publish" an app/update and the time until it appears on Play. Telling your users that there is an update when the update is unavailable would only lead to confusion and frustration.

    My advice: stick with Google's update notification system and don't worry about trying to get users an update 15 minutes sooner.

    0 讨论(0)
提交回复
热议问题