I am working on an application that displays Usage Stats for applications used on an android device. What I am trying to specifically do is chunk out usage time by day. So essentially, the end goal is to have a bar chart and each column is a total day's usage time.
I have implemented Usage
private long getWeekStartTime() {
Calendar calendar = Calendar.getInstance();
// Set it to 7 days prior
calendar.add(Calendar.DAY_OF_YEAR, -7);
return calendar.getTimeInMillis();
}
private long getEndTime(){
// Set end time to Now
return System.currentTimeMillis();
}
public void retrieveWeekUsageStats(){
List<UsageStats> usageStats = usageStatsManager.queryUsageStats(INTERVAL_DAILY,getWeekStartTime(), getEndTime());
for (UsageStats stat: usageStats) {
Log.d(TAG, "retrieveWeekUsageStats: " + stat.getPackageName() + " " + stat.getFirstTimeStamp() +" " + stat.getLastTimeStamp());
}
}
With the above code, I am able to log out a ton of packages that have been used recently but all of the packages and dates are intermixed.
I set the interval in the UsageStatsManager to INTERVAL_DAILY with the hopes that it would separate out the package uses into day intervals but it just spits everything out in a random order. What is the best way to sort this list into chunks by day?
I also tried to adjust the INTERVAL_DAILY to INTERVAL_WEEKLY with no avail.