Showing posts with label install. Show all posts
Showing posts with label install. Show all posts

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(),
                PackageManager.GET_ACTIVITIES);
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(TAG, "Can't get package info");
        }
    return (packageInfo.firstInstallTime != packageInfo.lastUpdateTime);
}