问题是,它需要3秒。我想每1000毫秒检查一次前台应用程序#THANKS_IN_ADVANCE

时间:2016-09-24 18:09:36

标签: android usagestatsmanager

UsageEvents usageEvent = mUsageStatsManager.queryEvents(time - 100 * 1000, time);
UsageEvents.Event event = new UsageEvents.Event();
// get last event
while (usageEvent.hasNextEvent()) {
  usageEvent.getNextEvent(event);
}
if (topPackageName.equals(event.getPackageName()) && event.getEventType() ==
    UsageEvents.Event.MOVE_TO_FOREGROUND) {
  pActivity = topPackageName;
}

1 个答案:

答案 0 :(得分:1)

the queryStats documentation

  

注意:事件日志的最后几分钟将被截断,以防止应用程序滥用。

所以这是按预期工作的。