Is there a way to programmatically get list of apps connecting to the internet and their inbound and outbound connection.
Thinking of doing an app that does this and do not need to root the phone.
Is there a way to programmatically get list of apps connecting to the internet and their inbound and outbound connection.
Thinking of doing an app that does this and do not need to root the phone.
If you want a low level solution you can try the netstat approach. On linux based systems you can read network information from /proc/net/route.
One way to do this is to to include a busybox binary in your app (make sure to look at the licencse) And run busybox netstat, then read the output into your app.
Process process = Runtime.getRuntime().exec("busybox netstat -n");
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream())
process.getOutputStream().close();
Then you can identify which app is using which connection by the process id column, you'll get the procces user which can be identified with an application such as app_23 , see this answer how to get the app name from the pid
If you don't want to include the busybox binary you can try reading the information from procfs yourself. Luckily someone already did that work for you, see this example.
This information is already available in settings under "DataUsage". You just have to extract it from there; have a look at - TrafficStats.
Similar question - about app level data consumption