如何知道哪些应用程序被打开? [英] How to know which app is opened?
本文介绍了如何知道哪些应用程序被打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要的任何应用程序打开时就知道了。显然地说,我做的服务,阻止某些应用程序(可根据用户),我想检查程序是此类似块列表任何应用程序,并终止该应用程序的过程。而且它需要root访问权限?
I want to know when any app is opened. Clearly to say, i am making service that blocks some apps ( according to user ) and i want to check app is this similar to any app in the blocklist and abort that app process. And does it need root access ?
推荐答案
使用此code
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> runtasks = activityManager.getRunningTasks(Integer.MAX_VALUE);
for (int i = 0; i < runtasks.size(); i++) {
Log.d("Running task", "Running task: " + runtasks.get(i).baseActivity.toShortString() + "\t\t ID: " + runtasks.get(i).id);
}
这篇关于如何知道哪些应用程序被打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文