在android低版本中获取已连接热点的ip使用如下方法:
private ArrayList getConnectIp() throws Exception {
ArrayList connectIpList = new ArrayList();
BufferedReader br = new BufferedReader(new FileReader("/proc/net/arp"));
String line;
while ((line = br.readLine()) != null) {
String[] splitted = line.split(" +");
if (splitted != null && splitted.length >= 4) {
String ip = splitted[0];
connectIpList.add(ip);
}
}
return connectIpList;
}
通过系统的arp列表得到。但是到了android10由于权限的问题无法获取到该文件。经过在网上查找和测试,可以通过如下方法的到,只需要修改上述代码的一部分
private ArrayList getConnectIp() throws Exception {
ArrayList connectIpList = new ArrayList();
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("ip neigh show");
proc.waitFor();
BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
//BufferedReader br = new BufferedReader(new FileReader("/proc/net/arp"));
String line;
while ((line = br.readLine()) != null) {
String[] splitted = line.split(" +");
if (splitted != null && splitted.length >= 4) {
String ip = splitted[0];
connectIpList.add(ip);
}
}
return connectIpList;
}
经过实际测试,可以获取到已连接设备的ip地址。
如果觉得《Android程序配置热点IP Android 10版本获取已连接本机热点的ip》对你有帮助,请点赞、收藏,并留下你的观点哦!