Follow by Email

Thursday, May 15, 2014

How to detect if application has been updated or installed

In some cases there is a need to know if user has installed or updated your app. For example to put different texts or something else. To do this you may use code below:
static public boolean isUpdated(Context ctx) {
    PackageInfo packageInfo = null;
    try {
            packageInfo = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(),
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(TAG, "Can't get package info");
    return (packageInfo.firstInstallTime != packageInfo.lastUpdateTime);

No comments:

Post a Comment

Post your comment here