It sounds like you just want your service to find what the foreground Activity is. You can find that information in other questions on StackOverflow, like this one. In short, you will want to use ActivityManager.getRunningTasks()
. The topmost Activity is the first item in the List.
It sounds like you will also need to request the appropriate permission in your app's manifest.