在android中,您可以通过观察Logcat来获取有关运行活动的信息。
例如,如果您打开相机,它将记录在Logcat中。
有没有办法以编程方式获取该信息?
答案 0 :(得分:10)
ActivityManager m = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE );
List<RunningTaskInfo> runningTaskInfoList = m.getRunningTasks(10);
Iterator<RunningTaskInfo> itr = runningTaskInfoList.iterator();
while(itr.hasNext())
{
RunningTaskInfo runningTaskInfo = (RunningTaskInfo)itr.next();
int id = runningTaskInfo.id;
CharSequence desc= runningTaskInfo.description;
String topActivity = runningTaskInfo.topActivity.getShortClassName();
int numOfActivities = runningTaskInfo.numActivities;
}
注意:您必须在清单文件中指定android.permission.GET_TASKS
权限。