java.lang.Object | |
↳ | android.app.usage.NetworkStatsManager |
Provides access to network usage history and statistics. Usage data is collected in
discrete bins of time called 'Buckets'. See NetworkStats.Bucket
for details.
querySummaryForDevice(int, String, long, long)
) collect only network usage of apps belonging to the same user
as the client. In addition tethering usage, usage by removed users and apps, and usage by system
is also included in the results.
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 and state combination. In case of the user-wide and device-wide
summaries a single bucket containing the totalised network usage is returned.
queryDetailsForUid(int, String, long, long, int)
queryDetails(int, String, long, long)
These queries do not aggregate over time but do aggregate over state. Therefore there can be
multiple buckets for a particular key but all Bucket's state is going to be
STATE_ALL
.
NOTE: This API requires the permission
PACKAGE_USAGE_STATS
, which is a system-level permission and
will not be granted to third-party apps. However, declaring the permission implies intention to
use the API and the user of the device can grant permission through the Settings application.
Profile owner apps are automatically granted permission to query data on the profile they manage
(that is, for any query except querySummaryForDevice(int, String, long, long)
). Device owner apps likewise get
access to usage data of the primary user.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Query network usage statistics details.
| |||||||||||
Query network usage statistics details.
| |||||||||||
Query network usage statistics summaries.
| |||||||||||
Query network usage statistics summaries.
| |||||||||||
Query network usage statistics summaries.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Query network usage statistics details. Result filtered to include only uids belonging to
calling user. Result is aggregated over state but not aggregated over time or uid. This means
buckets' start and end timestamps are going to be between 'startTime' and 'endTime'
parameters, state is going to be STATE_ALL
and uid will vary.
Only includes buckets that atomically occur in the inclusive time range. Doesn't interpolate across partial buckets. Since bucket length is in the order of hours, this method cannot be used to measure data usage on a fine grained time scale.
networkType | As defined in ConnectivityManager , e.g.
TYPE_MOBILE , TYPE_WIFI
etc. |
---|---|
subscriberId | If applicable, the subscriber id of the network interface. |
startTime | Start of period. Defined in terms of "Unix time", see
currentTimeMillis() . |
endTime | End of period. Defined in terms of "Unix time", see
currentTimeMillis() . |
SecurityException | |
---|---|
RemoteException |
Query network usage statistics details. Only usable for uids belonging to calling user.
Result is aggregated over state but not aggregated over time. This means buckets' start and
end timestamps are going to be between 'startTime' and 'endTime' parameters, state is going
to be STATE_ALL
and uid the same as the 'uid' parameter.
Only includes buckets that atomically occur in the inclusive time range. Doesn't interpolate across partial buckets. Since bucket length is in the order of hours, this method cannot be used to measure data usage on a fine grained time scale.
networkType | As defined in ConnectivityManager , e.g.
TYPE_MOBILE , TYPE_WIFI
etc. |
---|---|
subscriberId | If applicable, the subscriber id of the network interface. |
startTime | Start of period. Defined in terms of "Unix time", see
currentTimeMillis() . |
endTime | End of period. Defined in terms of "Unix time", see
currentTimeMillis() . |
uid | UID of app |
SecurityException | |
---|---|
RemoteException |
Query network usage statistics summaries. Result filtered to include only uids belonging to calling user. Result is aggregated over time, hence all buckets will have the same start and end timestamps. Not aggregated over state or uid. This means buckets' start and end timestamps are going to be the same as the 'startTime' and 'endTime' parameters, state and uid are going to vary.
networkType | As defined in ConnectivityManager , e.g.
TYPE_MOBILE , TYPE_WIFI
etc. |
---|---|
subscriberId | If applicable, the subscriber id of the network interface. |
startTime | Start of period. Defined in terms of "Unix time", see
currentTimeMillis() . |
endTime | End of period. Defined in terms of "Unix time", see
currentTimeMillis() . |
SecurityException | |
---|---|
RemoteException |
Query network usage statistics summaries. Result is summarised data usage for the whole
device. Result is a single Bucket aggregated over time, state and uid. This means the
bucket's start and end timestamp are going to be the same as the 'startTime' and 'endTime'
parameters, state is going to be STATE_ALL
and uid
UID_ALL
.
networkType | As defined in ConnectivityManager , e.g.
TYPE_MOBILE , TYPE_WIFI
etc. |
---|---|
subscriberId | If applicable, the subscriber id of the network interface. |
startTime | Start of period. Defined in terms of "Unix time", see
currentTimeMillis() . |
endTime | End of period. Defined in terms of "Unix time", see
currentTimeMillis() . |
SecurityException | |
---|---|
RemoteException |
Query network usage statistics summaries. Result is summarised data usage for all uids
belonging to calling user. Result is a single Bucket aggregated over time, state and uid.
This means the bucket's start and end timestamp are going to be the same as the 'startTime'
and 'endTime' parameters, state is going to be STATE_ALL
and uid
UID_ALL
.
networkType | As defined in ConnectivityManager , e.g.
TYPE_MOBILE , TYPE_WIFI
etc. |
---|---|
subscriberId | If applicable, the subscriber id of the network interface. |
startTime | Start of period. Defined in terms of "Unix time", see
currentTimeMillis() . |
endTime | End of period. Defined in terms of "Unix time", see
currentTimeMillis() . |
SecurityException | |
---|---|
RemoteException |