everyone. I have an assignment where I need to get some user data using android, and one of the data items that I must retrieve is the name of the application that is currently being used by the user eg. Say the user is using the Camera application, I need to be able to show that the user is using the Camera application using code. Is there any way do this? Any help would be much appreciated.
Asked
Active
Viewed 1,940 times
2 Answers
0
You can try this code it gives the package of the currently active screen:
ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
// get the info from the currently running task
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
if(!componentInfo.getPackageName().equals("your.package.name")) {
//Do your stuff
}
You might need the permission
<uses-permission android:name="android.permission.GET_TASKS" />

activesince93
- 1,716
- 17
- 37
0
This method will be helpful , ActivityManager.getRunningAppProcesses() check this ,
-
Thanks, but this segment of code gives me a list of currently running applications. How can I get to the one that is at the top of list? – D Brown Apr 15 '11 at 05:20
-
How can I do it via adb? – JohnyTex Aug 16 '18 at 13:11