Pergunta

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

Foi útil?

Solução

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 em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top