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

1k views Asked by At

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?

2

There are 2 answers

0
davi albuquerque On BEST ANSWER

You need to query by UID and pass in the tethering UID: android.app.usage.NetworkStats.Bucket.UID_TETHERING like so:

networkStatsManager.queryDetailsForUid(ConnectivityManager.TYPE_MOBILE,
    subscriberId, startDate, endDate, 
    android.app.usage.NetworkStats.Bucket.UID_TETHERING);
0
Noe Adrian Acuña Prado On

What I did was to get the data from this files

/sys/class/net/< interface>/statistics/tx_bytes

/sys/class/net/< interface>/statistics/tr_bytes

then I saved the values using sharedpreference y made some code also for getting just the new values and add it to the saved values.

I made a lot of research but queryDetailsForUid using UID_TETHERING never worked

the interfaces are wlan and wwan