How to monitoring app swaping in foreground?

社会主义新天地 提交于 2019-12-06 09:29:53

For monitoring other Applications you can use ActivityManager for getting current top Appliction for Activity Stack as in Your Appliction:

ActivityManager am = (ActivityManager)context.getSystemService(Context. ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> processes1 = activityManager.getRunningTasks(1);
ComponentName componentInfo = processes1.get(0).topActivity;
String classname =processes1.get(0).topActivity.getClassName(); 
String packagename = processes1.get(0).topActivity.getPackageName();

we can’t use getRunningTasks because android specifies “method is only intended for debugging and presenting task management user interfaces“.

There is no direct approach to get the app status while background or foreground, but there is possibility of getting to know when app is foreground and background For more details: See here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!