I have a service running on Android, and I need to know if there is any application in focus or if the “desktop” (main screen) is in focus. I do not know if this is suitable to indicate the main screen of the phone. How can I find out if this is in focus or some other application?
Inside the service, I have this code to perform the tasks that are performed:
ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
How can I find out from componentInfo if this is the desktop or not? In the emulator, componentInfo.getPackageName () returns com.android.launcher , but in the galaxy s1 (I tested only on this phone), it returns something else.
Is there any other way to do this?
Thank.
source
share