Is it possible to query the age of an android device? I want to know, how long a user owns his device. The age of the battery might be a good indicator, but I cannot find an app
There is no solid way to find out the device age but yes somehow we can figure out the age.
Android devices are packaged with some pre-installed apps(Sytem applications) and when user owns it, he installs other apps(User applications). We can find out date of earliest installed user app and can predict the device age.
* If device has been reset after use, it would be difficult to find device age.
// @return earliest installed app's date.
private static String getOldestAppsAge(Context context) {
long appsAge = 0;
try {
appsAge = System.currentTimeMillis();
PackageManager pkgManager = context.getPackageManager();
List lsApp = pkgManager.getInstalledApplications(0);
for (ApplicationInfo localApplicationInfo : lsApp) {
String pkgName = localApplicationInfo.packageName;
if ((localApplicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
PackageInfo info = pkgManager.getPackageInfo(pkgName, 0);
long firstInstallTime = info.firstInstallTime;
if (firstInstallTime < appsAge && firstInstallTime > sGINGER_RELEASE_DATE) {
appsAge = info.firstInstallTime;
}
}
}
} catch (PackageManager.NameNotFoundException ex) {
ex.printStackTrace();
}
return DateUtils.convertIntoDesiredDateFormat(appsAge);
}