I got code that will display all apps running on device (package name and app name). I need time how long they have been used. How I can do that? Please.
ActivityManager manager =(ActivityManager)getSystemService(ACTIVITY_SERVICE);
final List<ActivityManager.RunningAppProcessInfo> runningProcesses = manager.getRunningAppProcesses();
StringBuilder b = new StringBuilder();
PackageManager pm = this.getPackageManager();
for (ActivityManager.RunningAppProcessInfo process: runningProcesses)
{
try
{
b.append (pm.getApplicationLabel(pm.getApplicationInfo(process.processName, PackageManager.GET_META_DATA)));
}
catch (Exception e)
{
b.append("Unknown");
}
b.append(System.getProperty("line.separator"));
b.append(process.processName);
b.append(System.getProperty("line.separator"));
//here the run time of an application
b.append(System.getProperty("line.separator"));
b.append("---------------------------------------------------");
b.append(System.getProperty("line.separator"));
}
processesShow=(TextView) this.findViewById(R.id.citac);
processesShow.setText(b.toString());