try {
// Executes the command.
Process process = Runtime.getRuntime().exec("/system/bin/ls /sdcard");
// Reads stdout.
// NOTE: You can write to stdin of the command using
// process.getOutputStream().
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
reader.close();
// Waits for the command to finish.
process.waitFor();
return output.toString();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
2 回答
在手机上查看文件:/ proc / net / arp .
它具有连接到同一网络的所有其他设备的IP和MAC地址 . 但是,我担心如果他们是Android手机,你将无法区分 .
您将需要使用tcpdump将网卡置于promiscous模式,然后捕获数据包以识别网络中的其他客户端 .
如何在android上使用tcpdump:http://source.android.com/porting/tcpdump.html
您可以在代码中运行命令,如下所示: