help wanted
Repository metrics
- Stars
- (33,679 stars)
- PR merge metrics
- (30d に merged PR はありません)
説明
These 2 features are important and useful to have in AppUtils. it is to detect whether the current app is installed newly, or got upgraded from a lower version. There are many use cases for this functionality.
Check if first install:
public static boolean isFirstTimeInstalled(Context context) {
try {
long firstInstallTime = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).firstInstallTime;
long lastUpdateTime = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).lastUpdateTime;
return firstInstallTime == lastUpdateTime;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return true;
}
}
Check if app is upgraded:
public static boolean isAppUpgraded(Context context) {
try {
long firstInstallTime = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).firstInstallTime;
long lastUpdateTime = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).lastUpdateTime;
return firstInstallTime != lastUpdateTime;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return false;
}
}
Thank you and good luck!