I would like to monitor the traffic of my mobile hotspot.

I found TrafficStats.getTotalRxBytes but this won't let me monitor precisely the usage of the android mobile hotspot function (or any other app). How can I access the statistic of the data usage menue?

有帮助吗?

解决方案

I found TrafficStats.getTotalRxBytes but this won't let me monitor precisely the usage of the android mobile hotspot function (or any other app).

TrafficStats have other methods -- such as getUidTxBytes() -- that let you monitor traffic by UID, which roughly equates to app. However, it may require some experimentation for you to determine what exactly will contain "the android mobile hotspot function", and it is not out of the question that this is not covered by TrafficStats, at least at the UID level.

You are welcome to examine the AOSP Settings app to see how the data usage screen is implemented, though I suspect nothing in there is visible to you in the Android SDK other than TrafficStats.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top