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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions lib/utilcode/src/main/java/com/blankj/utilcode/util/AppUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,38 @@ public static int getAppIconId(final String packageName) {
}
}


/**
* 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;
}
}


/**
* Return the application's package name.
*
Expand Down