【问题标题】:receive notifications when users connected an WIFI access point当用户连接 WIFI 接入点时接收通知
【发布时间】:2014-01-21 14:38:03
【问题描述】:

我想定义到我的接入点的连接。我想在用户连接时收到通知。 我知道我可以查询 arp table(/proc/net/arp) ,从中我可以找到连接的用户。这是示例代码:

public static ArrayList<ClientScanResult> getClientList() {
    BufferedReader br = null;
    ArrayList<ClientScanResult> result = null;

    try {
        result = new ArrayList<ClientScanResult>();
        br = new BufferedReader(new FileReader("/proc/net/arp"));
        String line;
        while ((line = br.readLine()) != null) {
            String[] splitted = line.split(" +");
            Log.d("Debug:line=", line);
            if ((splitted != null) && (splitted.length >= 4)) {
                // Basic sanity check
                String mac = splitted[3];

                if (mac.matches("..:..:..:..:..:..")) {
                    result.add(new ClientScanResult(splitted[0], splitted[3], splitted[5]));
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return result;
}

问题:除了每隔 n 秒查看一次 arp-table 之外,还有什么更好的方法吗?

UPD: 如果你连接到一个接入点,然后断开连接,那么记录仍然会在 arp-table 中。也就是说,直到我无法获得所有连接用户的列表

【问题讨论】:

  • 清单中的 Wifi 状态权限
  • @Boopathi。是的。他在那里
  • 在您的应用程序中授予 wifi 权限
  • @Boopathi ''

标签: android wifi access-point


【解决方案1】:

【讨论】:

  • 然后我将能够确定何时连接到我的接入点?
  • 我发现只有一个广播接收器与接入点 (WIFI_AP_STATE_CHANGED_ACTION) 相关联。而且他只跟踪接入点的状态,但我想要连接到接入点的状态
  • 这是运行代码的触发器...而不是每隔几秒运行一次
  • 你无法解释?我捕捉到了这个动作?
  • 我注意到在连接日志中写入 I/hostapd:wlan0: AP-STA-CONNECTED 00:21:e9:dc:07:85
猜你喜欢
  • 1970-01-01
  • 2013-02-11
  • 1970-01-01
  • 2011-11-05
  • 1970-01-01
  • 1970-01-01
  • 2015-08-31
  • 2017-07-17
  • 1970-01-01
相关资源
最近更新 更多