0

I tried using

List<UsageStats> stats2 = usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, 0, time); 

to get a list of UsageStats objects for all installed apps but it only returns a max of 25 for some reason. I didn't see a method to get the UsageStats for a specific package name in UsageStatsManager.

I was planning on using ApplicationInfo getInstalledApplications() to get a more accurate list but couldn't see how to get UsageStats from it. Does anyone know how to solve my problem?

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104
John61590
  • 1,106
  • 1
  • 13
  • 29

1 Answers1

1

You can use queryAndAggregateUsageStats merges the resulting UsageStats data and keys it by package name.

Map<String, UsageStats> aggregatedStatsMap= usageStatsManager.queryAndAggregateUsageStats(start, end);
//Get stats for particular package as follows:
UsageStats usageStats= aggregatedStatsMap.get("<packageName>");
Sagar
  • 23,903
  • 4
  • 62
  • 62
  • reasonable answer, but the method does not give a map that has all of the installed packages in it. – John61590 Jul 10 '18 at 18:26
  • @John61590 You just need to increase the time interval. The usage stats are returned for those apps which has usage in that interval. All apps might not have been used by user in this interval. – Sagar Jul 16 '18 at 01:41
  • well the interval was from 1970 (0, unix epoch time) to the current so it should be good right? – John61590 Jul 17 '18 at 00:49
  • @John61590 yeah. It should be good. You also need to consider that, some apps are pre-installed but never used. – Sagar Jul 17 '18 at 00:53