Skip to content

Commit 293fa10

Browse files
authored
Merge pull request Blankj#1491 from NotNotMarshall/patch-3
NEW Methods: AppUtils: isFirstTimeInstall(), isAppUpgraded() (All APIs supported)
2 parents 57fbefa + 20290bb commit 293fa10

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

lib/utilcode/src/main/java/com/blankj/utilcode/util/AppUtils.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,38 @@ public static int getAppIconId(final String packageName) {
384384
}
385385
}
386386

387+
388+
/**
389+
* Return true if this is the first ever time that the application is installed on the device.
390+
*
391+
* @return true if this is the first ever time that the application is installed on the device.
392+
*/
393+
public static boolean isFirstTimeInstall(){
394+
try {
395+
Long firstInstallTime = Utils.getApp().getPackageManager().getPackageInfo(this.getAppPackageName(), 0).firstInstallTime;
396+
Long lastUpdateTime = Utils.getApp().getPackageManager().getPackageInfo(this.getAppPackageName(), 0).lastUpdateTime;
397+
return firstInstallTime == lastUpdateTime;
398+
} catch (Exception e) {
399+
return false;
400+
}
401+
}
402+
403+
/**
404+
* 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.
405+
*
406+
* @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.
407+
*/
408+
public static boolean isAppUpgraded(){
409+
try {
410+
Long firstInstallTime = Utils.getApp().getPackageManager().getPackageInfo(this.getAppPackageName(), 0).firstInstallTime;
411+
Long lastUpdateTime = Utils.getApp().getPackageManager().getPackageInfo(this.getAppPackageName(), 0).lastUpdateTime;
412+
return firstInstallTime != lastUpdateTime;
413+
} catch (Exception e) {
414+
return false;
415+
}
416+
}
417+
418+
387419
/**
388420
* Return the application's package name.
389421
*

0 commit comments

Comments
 (0)