I am looking at my results from using:
List<UsageStats> usageStatsList = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, startTime,endTime);
where startTime in just after midnight, and endTime is just before midnight the same day.
Example result:
Pkg: com.android.chrome ForegroundTime: 6412 seconds Time last used: Thu Apr 19 22:31:17 PDT 2018
Pkg: com.instagram.android ForegroundTime: 5415 seconds Time last used: Thu Apr 19 23:11:22 PDT 2018
Pkg: com.android.chrome ForegroundTime: 5304 seconds Time last used: Thu Apr 19 03:00:49 PDT 2018
Pkg: com.instagram.android ForegroundTime: 5202 seconds Time last used: Thu Apr 19 03:00:45 PDT 2018
As you can see, it returns the same package twice for some things, with different time last used, even though both time last used were during the 24hr interval I specified.
I have looked at a bunch of other results here: Android UsageStatsManager producing wrong output?
but can't seem to fix my problem.
Does anyone know why it behaves this way? It seems to be time dependent? And the time last used always says 3am for some packages, despite me being fast asleep at that time?