John61590
John61590

Reputation: 1106

Retrieve UsageStats for a specific package

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?

Upvotes: 0

Views: 1443

Answers (1)

Sagar
Sagar

Reputation: 24927

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>");

Upvotes: 2

Related Questions