-1

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.

Shawn Sim
  • 545
  • 1
  • 5
  • 17
  • There are existing apps like "Network Connections" (https://play.google.com/store/apps/details?id=com.antispycell.connmonitor&hl=en)That does this. Where can I find source codes to does this? – Shawn Sim May 30 '17 at 01:47

2 Answers2

1

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.

ApriOri
  • 2,618
  • 29
  • 48
  • I second the netstat approach. BTW: nice find, this netinfo project, assuming it works. I'll only add two cents about rooting the device - you don't have to, you can set this monitoring application as a device administrator. This is what every AV needs and they do monitor network connectoins and filesystem changes (my ESET Mobile does this). – Kitet Jun 25 '17 at 22:06
0

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

Gaurav
  • 559
  • 4
  • 8