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
That's an interesting question. There's no API to tell when the device was first purchased - but you can look for proxies.
None of those are perfect, but they can be used to put some bounds on when the user first got their device.
There are a few difficulties you may need to consider here:
1) Most android devices have (easily) removable batteries. I, for one, have several batteries that I alternate between when I use my phone.
2) Even if timestamps had been collected on boot, they would likely be deleted if the phone's owner wipes the device to install different ROMs.
I'd expect jcollum's solution of attempting to determine the model of the phone, or look at some piece of its hardware and determine an approximate release date of the model might be your closest solution. I doubt you'll find much accuracy in determining the age of the actual device. If there is, however, please correct me - I'm curious about this now too!
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<ApplicationInfo> 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);
}