Questions tagged [android-trafficstats]

27 questions
26
votes
3 answers

StrictMode java.lang.Throwable: Untagged socket detected

With StrictMode enabled I just started getting this exception: java.lang.Throwable: Untagged socket detected; use TrafficStats.setThreadSocketTag() to track all network usage
Jose Gómez
  • 3,110
  • 2
  • 32
  • 54
9
votes
1 answer

NetworkStatsManager.queryDetailsForUid not obtaining the "same" values as TrafficStats

I'm comparing the new NetworkStats class with TrafficStats for measuring traffic for the network interfaces and a given application (pex Chrome) Since TrafficStats has values since device boot the test that I'm performing is this: Reboot phone.…
Favolas
  • 6,963
  • 29
  • 75
  • 127
7
votes
2 answers

getUidTxBytes(int uid) always return 0 in android 6.0

I am trying to get network traffic stats of all apps. I just print total network traffic of every application in my device. The code is working fine in android 4.4 and 5.1 devices but in android 6.0 device it always return 0 for all applications.…
6
votes
2 answers

How to get the GPRS Mobile data usage for 1 month?

I have searched a lot about this. Found the same code everywhere which solves the purpose partially. As API documentation says, it reset the counter once the device restarts. Sometimes the counter just resets even without the restart. Below is the…
Bharat
  • 750
  • 1
  • 9
  • 20
5
votes
1 answer

TrafficStats.getMobileRxBytes() and TrafficStats.getMobileTxBytes() always return 0 in Nexus 5x

I am trying to fetch mobile data usage using TrafficStats. Example: mobileDataUsage = TrafficStats.getMobileRxBytes() +TrafficStats.getMobileTxBytes() totalUsage = TrafficStats.getTotalRxBytes() + TrafficStats.getTotalTxBytes() In few devices it is…
4
votes
1 answer

How to count separately data usage in 2G and 3G with TrafficStats?

How can I mix/join the following two codes in order to count TX and RX bytes separately when the phone is in 2G or 3G? I have the following code to identify when the phone is connected to EDGE or UMTS network that seems to work, showing a Toast…
4
votes
3 answers

Android mobile usage history NetworkStatsManager

I'm making an App for Android 6.0 and I want to use the new class NetworkStatsManager for getting mobile data usage. I added all permission I need in manifest and require the permission runtime. When I call the method: bucket =…
Allen Walker
  • 866
  • 1
  • 9
  • 17
3
votes
0 answers

How to show daily total internet data usage by android programmatically?

I want to show the user how much internet data he consumed from 12am of that day till he checks, like the Datally app by google. I know that we can see the total data usage after last reboot using TrafficStats class's getTotalRxBytes and…
3
votes
1 answer

NetworkStatsManager's queryDetailsForUid() method always returns old network usage for all the apps

I have written a code to get network usage but queryDetailsForUid(int networkType, String subscriberId,long startTime, long endTime, int uid) this method always returns old data. How can I get updated data…
2
votes
1 answer

How to get trafficstats from a specific thread

On android, how can I use TrafficStats and TrafficStatsCompat to get the total TX bytes for a specific thread in the current process? The API implies that it's possible but I can't figure it out.
Jakob Eriksson
  • 18,597
  • 1
  • 25
  • 34
1
vote
1 answer

Bad value returned by TrafficStats

My Android app (running Android 10) uses network traffic statistics. When my device is on Wifi, TrafficStats.getMobileTxBytes and ...getMobileRxBytes return always 0. When it switches on Cellular network, returned values look good. Any idea or…
1
vote
0 answers

How to get mobile data usage of current month without monitoring it periodically using API 22 or less?

I need to know how much mobile data the device has used since the start of the current month, I know how to do it monitoring the device, but there are two problems with this: 1 - The device I'm working with has very low performance, the network is…
1
vote
1 answer

Android: difference between data usage on a hotspot phone and on a phone using it

I am trying to compare the data usage difference between a phone using an other phone's hotspot and the hotspot of the phone. On the phone having its hotspot turned on, I am using this code to compute the data usage of the hotspot(The result is…
Bazouk55555
  • 557
  • 6
  • 24
1
vote
2 answers

How to get Tethering and Mobile Hotspot data usage in Android using NetworkStatusManager or TrafficStat

I have an Android application which displaying data usage per app by NetworkStatusManager, but I can't get data usage for Tethering and Mobile Hotspot. How should I do this?
1
vote
0 answers

Is there any alternative to NetworkStatsManager?

I'm looking for an alternative way to get the number of bytes received & transmitted by a specific UID on android M+. As you know, [NetworkStatsManager] provides network traffic stats. These statistics include bytes transmitted and received and…
1
2