我目前使用以下代码来获取有关 Activity 网络套接字的一些信息。到目前为止,我已经确认这适用于 Nexus 4 (Jellybeans)、Nexus 5 (Jellybeans、KitKat 和 Lollipop) 和 Sony Xperia 设备 (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();
我能否依靠上述代码在大多数真实 Android 设备上正常运行?
最佳答案
大部分 Android shell 命令都位于设备的/system/bin 文件夹中。 Vanilla Android 使用包含 netstat 的 FreeBSD 工具箱,但我不确定您是否可以 100% 确定它会一直存在,因为 OEM 有时会附带不同的工具。这是工具箱中包含的工具的图表:
您可以查看 source对于 vanilla Android 查看什么版本附带什么。但正如我所说,每个制造商随每台设备提供的产品可能会有所不同。
关于android - 'netstat' 命令在 Android 上是否普遍可用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28681066/