Create the following. Show the list of all apps installed in a phone and display
ID: 3860440 • Letter: C
Question
Create the following. Show the list of all apps installed in a phone and display the time it has been used. The time indicates how long each app is used by the user. Not counting the time running in the background. This must be completed using Android Studio.
Can someone help me create this for my lab. All it has to do is display the applications installed in the users phone, and display the total time they used the app. Only in the foreground. Not the background. If they close an app, the timer should stop. And it would restart everyday. This image is the example of the result.
Pocket Skype WhatsApp App Usage Tracker Messaging Google Search 18m 30s 8m 4s 1m 52s 52s 21s 8sExplanation / Answer
Basically, how do I detect when an activity is launched?
You can see below and use the code
Below code can be used in service to get foreground running app:
ActivityManager am = (ActivityManager) AppService.this.getSystemService(ACTIVITY_SERVICE);
// The first in the list of RunningTasks is always the foreground task.
RunningTaskInfo foregroundTaskInfo = am.getRunningTasks(1).get(0);
Then details about can be found using below code easily
String foregroundTaskPackageName = foregroundTaskInfo .topActivity.getPackageName();
PackageManager pm = AppService.this.getPackageManager();
PackageInfo foregroundAppPackageInfo = pm.getPackageInfo(foregroundTaskPackageName, 0);
String foregroundTaskAppName = foregroundAppPackageInfo.applicationInfo.loadLabel(pm).toString();
Add below permission to manifest file for above to work..
<uses-permission android:name="android.permission.GET_TASKS" />
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.