Reputation: 1109
I currently use the following code to obtain some information on active network sockets. So far I've confirmed that this works on Nexus 4 (Jellybeans), Nexus 5 (Jellybeans, KitKat and Lollipop) and a Sony Xperia device (Jellybeans).
Process process = Runtime.getRuntime().exec("netstat -n");
process.getOutputStream().close();
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readline()) != null) {
// Parse line for required info
}
reader.close();
Can I rely on the the above code to function properly on the majority of real-world Android devices out there?
Upvotes: 2
Views: 17745
Reputation: 2946
The Android shell commands are, most of them, found in the /system/bin folder on the device. Vanilla Android uses the FreeBSD Toolbox that contains netstat, but I'm not sure if you can be 100% sure that it will always be around since the OEM's sometimes ship with different tools. Here is a diagram of the tools contained in the toolbox:
You can go over the source for vanilla Android to see what ships with what version. But like I said, there might be differences in what each manufacturer ships with each device.
Upvotes: 7