1

I need to get Data Usage history of Android device.

Which of these features can I have ? and how ?

1-Daily data usage or even hourly.

2-From the last device data wipe date to now.

3-Contains application details.

Attention

I don't want to monitor and save data usage history.

I want to have it all after installing the application.

**Please** tell if there is more than one way And also if thy need Root access 
Or if they work on a specific API version.
M at
  • 1,020
  • 1
  • 12
  • 26

1 Answers1

1

Back in old ages, I wanted to capture data usage of the device without monitoring it. The only method that I know back then was to capture every thing using a service in background and I thought that would be CPU heavy. (TrafficStats was the only way to go back then)

To answer the question for others who might see it I should say the following.

  • From API 23 there is a function called NetworkStatsManager that can do this. I should Also link to this answer and his work on github.
  • According to google document you can get data usage for any period of time between Long.MIN_VALUE and Long.MAX_VALUE.

    Queries can define a time interval in the form of start and end timestamps (Long.MIN_VALUE and Long.MAX_VALUE can be used to simulate open ended intervals).

  • You can get usage of other applications classified based on their UID that you can then turn to package name and etc. (Referral project)

  • There are 5 ways of doing so as in the documentation.

    Summary queries

    querySummaryForDevice(int, String, long, long)

    querySummaryForUser(int, String, long, long)

    querySummary(int, String, long, long)

    These queries aggregate network usage across the whole interval. Therefore there will be only one bucket for a particular key, state, metered and roaming combination. In case of the user-wide and device-wide summaries a single bucket containing the totalised network usage is returned.

    History queries

    queryDetailsForUid(int, String, long, long, int)

    queryDetails(int, String, long, long)

    These queries do not aggregate over time but do aggregate over state, metered and roaming. Therefore there can be multiple buckets for a particular key. However, all Buckets will have state NetworkStats.Bucket.STATE_ALL, defaultNetwork NetworkStats.Bucket.DEFAULT_NETWORK_ALL, metered NetworkStats.Bucket.METERED_ALL, roaming NetworkStats.Bucket.ROAMING_ALL.

M at
  • 1,020
  • 1
  • 12
  • 26