我如何知道运行中的顶级应用程序的软件包名称。
https://www.dropbox.com/s/2p4iuj7dj7zv5u4/Screenshot%20%28234%29.png
(在链接中,上面的应用程序为Temple run 2,程序包为com.imangi.templerun2)
我需要从服务中检索包名称(即com.imangi.templerun2),并将其存储在名为packageName的字符串中。我该怎么做 ???
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
// Return a list of the tasks that are currently running,
// with the most recent being first and older ones after in order.
// Taken 1 inside getRunningTasks method means want to take only
// top activity from stack and forgot the olders.
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
componentInfo.getPackageName(); // here it is
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句