Is it possible to use android to detect if a certain app on an android phone is open on the screen. For example, checking to see if the user is currently using his/her photo's app. Most of the questions I've read so far are checking the whether a certain BACKGROUND app is running; I'm trying to figure out whether I can check if a certain app is currently open and running on the screen. So using my app (which would be running in the background) to detect whether an app, for example the photos app, is open and being used by the user.
Asked
Active
Viewed 6,210 times
2
-
I think this is what you are looking for: http://stackoverflow.com/questions/6064137/can-an-android-application-know-when-another-android-application-is-running – Dani Ivanov Jan 05 '16 at 14:43
-
@DaniIvanov that's not exactly what I'm looking for because I'm wondering whether it's possible to see if an app is currently running on the screen, not in the background. – Dude1310 Jan 05 '16 at 14:45
-
@FireSun No, that's not what I'm asking for. I'm not asking for background apps. I'm asking whether an app is currently open on the screen. – Dude1310 Jan 05 '16 at 14:58
1 Answers
2
ActivityManager am =(ActivityManager)context.getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
ActivityManager.RunningTaskInfo task = tasks.get(0); // current task
ComponentName rootActivity = task.baseActivity;
String currentPackageName = rootActivity.getPackageName();
if(currentPackageName.equals("com.sec.android.gallery3d")) {
//Do whatever here
}
Use currentPackageName to see if it is the application you want.
For More Info, Look Here: Android: How can I get current opened application name on screen
EDIT: Also, you should add this permission
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />

Community
- 1
- 1

Hunter Copp
- 539
- 7
- 14