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.