2

I need to be able to detect the current foreground app. I am currently using the following:

    // get foreground app
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> tasks = manager.getRunningAppProcesses();
    foregroundApp = tasks.get(0).processName;

but starting with 5.1.1 getRunningAppProcesses returns only my app name.

According this bug ticket I need to use permission.REAL_GET_TASKS: https://code.google.com/p/android-developer-preview/issues/detail?id=2347

but this doesn't seem to work, how do I get that permission to work? I've tried upgrading my SDK.

Andrew
  • 3,545
  • 4
  • 31
  • 37

1 Answers1

3

how do I get that permission to work?

Build your own custom ROM, sign that ROM with the same signing key as you use for your app, and install the ROM and the app on your device. REAL_GET_TASKS is a signature-level permission; it cannot be held by ordinary Android SDK apps.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I see, so I could only use it for debugging type purposes, etc. Not production use? – Andrew Oct 17 '15 at 00:27
  • 2
    You could only use it for production use on custom devices where you created not only the app, but the installation of Android which they are running as well. Likely whatever you are trying to accomplish is a goal which is officially considered undesirable (at least for a third party to attempt), and that is why it has been blocked. – Chris Stratton Oct 17 '15 at 01:27