Search code examples
androidandroid-networking

Monitor Network usage of a process in android


I am developing on a custom Android based platform. I wanted to know if there is a way to monitor the network usage of a process in Android programmatically.

For Example

I have a service which keeps track of all the processes that are running in the device. This service wants also to track information of the network usage of a single process, and if it exceed on a prefixed value, the service force-kills it. Or maybe (it would be better), unless force killing it, it prevents the process from using network.

Since I'm developing in a custom platform so I can give my process any permission that I want, is there a way to achieve this?


Solution

  • Use TrafficStats, either directly or by examining how it is implemented so your custom OS modifications can get at the underlying implementation.