【问题标题】:Wifi devices are not getting cleared from the hotspot list when they are disconnected from the hotspot device与热点设备断开连接时,Wifi 设备未从热点列表中清除
【发布时间】:2012-09-13 20:46:53
【问题描述】:

我正在使用以下代码扫描连接到启用热点的设备的 wifi 设备。它正在检测几乎所有设备,但问题是当 wifi 设备与热点断开连接时列表没有刷新(即列表显示 wifi 设备,即使它们已断开连接,列表不应该显示设备已断开连接)。如果 wifi 设备连接到我的热点设备一次,它会在列表中显示 wifi 设备,并且设备列表在我不关闭热点之前不会刷新 以下是我的代码 sn-p...

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 设备断开连接时不会显示在列表中 有人请在这方面帮助我。 谢谢!

【问题讨论】:

    标签: java android android-wifi jvm-hotspot


    【解决方案1】:

    我不确定我的理解是否正确, 我对您的代码的以下行有疑问 String[] splitted = line.split(" +"); 您是否使用空格和 + 符号来连接设备的 MAC 地址。

    问候 阿吉尔

    【讨论】:

    • "/proc/net/arp" ---这包含用于地址解析的内核 ARP 表的 ASCII 可读转储。它将显示动态学习和预编程的 ARP 条目。格式为:“IP 地址”“硬件类型”“标志”“硬件地址”“掩码”“设备”....来分隔这些东西我正在使用 split
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 2022-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-09
    • 1970-01-01
    相关资源
    最近更新 更多