Pregunta

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

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top