I want to know the time spent by all applications running in an android device . I am getting all packages names using the following code .Please guide me how to link packages and the above method to get time spent by applications
Here is the code
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for (PackageInfo pack : packs) {
if (pack.firstInstallTime != pack.lastUpdateTime) {
Log.i("n-names",
pack.applicationInfo.loadLabel(getPackageManager())
.toString());
Log.i("n-install time", pack.firstInstallTime + "");
Log.i("n-uptime", pack.lastUpdateTime + "");
UsageStats usage = null;
usage.getTotalTimeInForeground();
}
}
Please tell me how to use the above methods for indivudual packages
If you want to get the foreground running time of all applications in android lollipop use the following piece of code.
//Variables with dummy values and objects.
Make sure you have all right permissions in manifest file and app have access with usage under security in settings.