Return amount in bytes of mobile data used per day

Asked

Viewed 27 times

2

Hello, I’m having a problem returning the amount in bytes of data consumed via mobile data on android.

I am currently using this code:

Calendar beginCal = Calendar.getInstance();
        beginCal.set(Calendar.DATE, 1);
        beginCal.set(Calendar.MONTH, 0);
        beginCal.set(Calendar.YEAR, 2015);

        Calendar endCal = Calendar.getInstance();
        endCal.set(Calendar.DATE, 1);
        endCal.set(Calendar.MONTH, 0);
        endCal.set(Calendar.YEAR, 2016);

        UsageStatsManager lUsageStatsManager = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
        final List<UsageStats> queryUsageStats= lUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_YEARLY, beginCal.getTimeInMillis(), endCal.getTimeInMillis());

But my queryUsageStats is returning 0. In this case I’m trying to take the 1 year period.

Would anyone know another way to return this data?

Thank you in advance.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.