Duration of the request interval

I am using the UsageStatsManager API to get usage statistics over a period of time. Everything works fine if I use predefined intervals, i.e. INTERVAL_DAILY, INTERVAL_WEEKLY, INTERVAL_MONTHLY, INTERVAL_YEARLY. But if I want to view the data for the last 2 or 3 hours, I get the data for the whole day today. I tried using Calendars and System.currentTimeMillis (), but that didn't give me filtered results.

Calendar approach:

Calendar startCalendar = Calendar.getInstance();
startCalendar.add(Calendar.HOUR_OF_DAY, -2);

Calendar endCalendar = Calendar.getInstance();

      

And pass that to the queryUsageStats method like this:

usageList = usm.queryUsageStats(interval, startCalendar.getTimeInMillis(), endCalendar.getTimeInMillis());

      

where the interval is INTERVAL_BEST.

System.currentTimeMillis () approach:

long startTime = System.currentTimeMillis() - 7200*1000 // 7200 seconds i.e. 2 hrs

long endTime = System.currentTimeMillis();

      

Pass this to queryUsageStats as above:

usageList = usm.queryUsageStats(interval, startTime, endTime);

      

where the interval is again INTERVAL_BEST.

I would like to know if it is possible to get data for this period, i.e. less than one day since INTERVAL_BEST was not documented correctly to include this information. Any help would be appreciated as I get stuck on this issue.

+3


source to share


1 answer


As the UsageStatsManager doc says:

A request for data in the middle of a time interval will include this interval.



It looks like the usage data is stored in buckets and the minimum bucket is a day, so you can't query usage statistics for a period of less than one day. Even if you request a one-hour interval for a specific day, usage statistics for the entire day are returned.

+2


source







All Articles