Skip to content

NEW Methods: AppUtils: isFirstTimeInstall(), isAppUpgraded() (All APIs supported) #1491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2021
Merged

NEW Methods: AppUtils: isFirstTimeInstall(), isAppUpgraded() (All APIs supported) #1491

merged 1 commit into from
Dec 5, 2021

Conversation

XiXiongMaoXiong
Copy link
Contributor

@XiXiongMaoXiong XiXiongMaoXiong commented May 4, 2021

  1. isFirstTimeInstall():
    If you want to know whether this is the first time installation of this app in this device.
  2. isAppUpgraded():
    If you want to know whether the current version was installed over a previous version (update/upgrade) or if it is freshly installed (clean install).

Code:

 * Return true if this is the first ever time that the application is installed on the device.
 *
 * @return true if this is the first ever time that the application is installed on the device.

public static boolean isFirstTimeInstall(){ try { Long firstInstallTime = Utils.getApp().getPackageManager().getPackageInfo(this.getAppPackageName(), 0).firstInstallTime; Long lastUpdateTime = Utils.getApp().getPackageManager().getPackageInfo(this.getAppPackageName(), 0).lastUpdateTime; return firstInstallTime == lastUpdateTime; } catch (Exception e) { return false; } }

 * Return true if app was previously installed and this one is an update/upgrade to that one, returns false if this is a fresh installation and not an update/upgrade.
 *
 * @return true if app was previously installed and this one is an update/upgrade to that one, returns false if this is a fresh installation and not an update/upgrade.

public static boolean isAppUpgraded(){ try { Long firstInstallTime = Utils.getApp().getPackageManager().getPackageInfo(this.getAppPackageName(), 0).firstInstallTime; Long lastUpdateTime = Utils.getApp().getPackageManager().getPackageInfo(this.getAppPackageName(), 0).lastUpdateTime; return firstInstallTime != lastUpdateTime; } catch (Exception e) { return false; } }

1. isFirstTimeInstall():
If you want to know whether this is the first time installation of this app in this device.
2. isAppUpgraded():
If you want to know whether the current version was installed over a previous version (update/upgrade) or if it is freshly installed (clean install).

Code:
/**
     * Return true if this is the first ever time that the application is installed on the device.
     *
     * @return true if this is the first ever time that the application is installed on the device.
     */
    public static boolean isFirstTimeInstall(){
        try {
            Long firstInstallTime = Utils.getApp().getPackageManager().getPackageInfo(this.getAppPackageName(), 0).firstInstallTime;
            Long lastUpdateTime = Utils.getApp().getPackageManager().getPackageInfo(this.getAppPackageName(), 0).lastUpdateTime;
            return firstInstallTime == lastUpdateTime;
        } catch (Exception e) {
            return false;
        }
    }

    /**
     * Return true if app was previously installed and this one is an update/upgrade to that one, returns false if this is a fresh installation and not an update/upgrade.
     *
     * @return true if app was previously installed and this one is an update/upgrade to that one, returns false if this is a fresh installation and not an update/upgrade.
     */
    public static boolean isAppUpgraded(){
        try {
            Long firstInstallTime = Utils.getApp().getPackageManager().getPackageInfo(this.getAppPackageName(), 0).firstInstallTime;
            Long lastUpdateTime = Utils.getApp().getPackageManager().getPackageInfo(this.getAppPackageName(), 0).lastUpdateTime;
            return firstInstallTime != lastUpdateTime;
        } catch (Exception e) {
            return false;
        }
    }
@XiXiongMaoXiong
Copy link
Contributor Author

@Blankj

@XiXiongMaoXiong XiXiongMaoXiong changed the title Added 2 very useful methods NEW Methods: AppUtils: isFirstTimeInstall(), isAppUpgraded() (All APIs supported) May 9, 2021
@XiXiongMaoXiong
Copy link
Contributor Author

@Blankj 他妈的,兄弟!?

@Blankj Blankj merged commit 293fa10 into Blankj:master Dec 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants