Issue
I run the following code on my device:
PackageManager packageManager = context.getPackageManager();
List<ApplicationInfo> applications = packageManager
.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo applicationInfo : applications) {
Log.OUT.debug("NET_THRESHOLD: package = " + applicationInfo.packageName + ", uid = " + applicationInfo.uid + ", rx bytes: " + TrafficStats.getUidRxBytes(applicationInfo.uid));
}
And it seems to report -1
(or TrafficStats.UNSUPPORTED
) for every package on my device except for the one I'm calling it from.
Is this intended behavior?
I'm running Android 10 if this makes a difference.
Solution
I just found this in the android documentation for TrafficStats#getUidRxBytes(int)
.
Starting in
Build.VERSION_CODES.N
this will only report traffic statistics for the calling UID. It will returnUNSUPPORTED
for all other UIDs for privacy reasons. To access historical network statistics belonging to other UIDs, useNetworkStatsManager
.
Answered By - Nathan F.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.