1

I know how to retrieve information about the foreground app:

public ActivityManager.RunningTaskInfo getForegroundTask()
{
    ActivityManager am = (ActivityManager) mContext.getSystemService( Activity.ACTIVITY_SERVICE );
    return am.getRunningTasks(1).get(0);
}

public String getForegroundTaskPackageName()
{
    return getForegroundTask().topActivity.getPackageName();
}

My question is, how can I know for sure that the foreground app is the launcher? I can't rely on the package name as it could be anything, like "com.android.launcher" or "com.htc.launcher".

Thanks

Xavi Gil
  • 11,460
  • 4
  • 56
  • 71
  • By combining your code above with this: http://stackoverflow.com/questions/10344824/how-can-i-get-the-package-name-of-the-current-launcher-in-android-2-3-and-above ? – class stacker Feb 07 '13 at 11:06
  • That is absolutely right. I swear I searched before asking :) Thanks. – Xavi Gil Feb 07 '13 at 11:10
  • ;) And I swear I didn't appreciate SO automatically considering my answer _trivial_ and turining it into a comment, so I wrote an answer again. – class stacker Feb 07 '13 at 11:14

1 Answers1

0

You can try to combine your code snippet to determine the package name of the foreground process with a call to PackageManager to get information about the HOME activity, as described here, and compare the results.

Community
  • 1
  • 1
class stacker
  • 5,357
  • 2
  • 32
  • 65