Levi
Levi

Reputation: 21

When I open wifi and connected, TrafficStats.getMobileRxBytes() and TrafficStats.getMobileTxBytes() always return 0

When I open wifi and connected, TrafficStats.getMobileRxBytes() and TrafficStats.getMobileTxBytes() always return 0, but close wifi, get the value is right.

Upvotes: 2

Views: 373

Answers (1)

AAryan
AAryan

Reputation: 20140

According to doc.

getMobileRxBytes return number of bytes received across mobile networks since device boot. Counts packets across all mobile network interfaces, and always increases monotonically since device boot.

And getMobileTxBytes return number of bytes transmitted across mobile networks since device boot. Counts packets across all mobile network interfaces, and always increases monotonically since device boot.

But it works according to doc only in Android 2 - 4. In Android 5 - 6 or even 7 it return zero when reconnect your mobile data.

There is an issue for the same. https://issuetracker.google.com/issues/37009612

Upvotes: 3

Related Questions