我使用以下代码扫描连接到启用Hotspot的设备的wifi设备。它正在检测几乎所有设备,但问题是当wifi设备与热点断开连接时列表没有刷新(即列表显示wifi设备,即使它们已断开连接,列表也不应显示设备哪些是断开的)。如果它连接到我的热点设备&在我关闭热点之前,设备列表没有刷新 以下是我的代码片段......
public ArrayList getClientList(boolean onlyReachables,int reachableTimeout){
BufferedReader br = null;
ArrayList<ClientScanResultSO> result = null;
try {
result = new ArrayList<ClientScanResultSO>();
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)) {
// Basic sanity check
String mac = splitted[3];
System.out.println("mac is***************"+ mac);
if (mac.matches("..:..:..:..:..:..")) {
boolean isReachable = InetAddress.getByName(splitted[0]).isReachable(reachableTimeout);
String name = InetAddress.getByName(splitted[0]).getHostName();
if (!onlyReachables || isReachable) {
result.add(new ClientScanResultSO(splitted[0], splitted[3], splitted[5], isReachable, name));
}
}
}
}
} catch (Exception e) {
Log.e(this.getClass().toString(), e.getMessage());
} finally {
try {
br.close();
} catch (IOException e) {
Log.e(this.getClass().toString(), e.getMessage());
}
}
return result;
}
我希望当wifi设备与启用了热点的Android设备断开连接时,不会在列表中显示这些设备 有人请在这方面帮助我。 谢谢!
答案 0 :(得分:0)
我不确定我的理解是否正确, 我对您的代码的以下行有所顾虑 String [] splitted = line.split(“+”); 您是否使用空格和+符号来连接设备的MAC地址。
此致 AJIL