1

I've had some success before with checking if the process name of the other application is running, but that will only tell me if the app has been running at some point recently, and would return true even if the screen was currently off. This time I'd like to actually know if the user has the particular application on screen and actively using it.

Would that be at all possible? Thanks!

GemmaB89
  • 165
  • 2
  • 16
  • Possible duplicate of [Determining the current foreground application from a background task or service](http://stackoverflow.com/questions/2166961/determining-the-current-foreground-application-from-a-background-task-or-service) – Tobias Nov 08 '15 at 17:20

2 Answers2

0

looks like all you want to do can be implemented using the ActivityManager class using its nested classes:

ActivityManager.RunningAppProcessInfo

ActivityManager.RunningServiceInfo

ActivityManager.RunningTaskInfo

ActivityManager.TaskDescription

what you need to do is to create a separate service that listens for other app events using these classes. I believe there was some method "getRunningTasks()" which returns list of all running apps, but I think its deprecated now, Search the links for similar methods.

praveen.jar
  • 83
  • 1
  • 10
0

No, at least not reliably.

Google has always stated that you should not do this. As of Lollipop, they are actively trying to prevent it. ActivityManager#getRunningTasks(...) was changed in Android 5.0 so it only returns information about the app calling it. So people started using ActivityManager#getRunningAppProcesses(...), but this was similarly restricted in Android 5.1.1 and 6.0.

The only sanctioned way to obtain information about other running apps is through the Usage Stats API. But that API requires a permission that can only be granted interactively through a system activity, not in the app's manifest. And the documentation states that the system activity may not be present on all devices. Manufacturers that have removed it from at least some of their devices include Samsung and LG.

Basically, barring the discovery of some new hack, third-party app lockers are history as of Android 6.

Kevin Krumwiede
  • 9,868
  • 4
  • 34
  • 82