首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED替代

android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED替代
EN

Stack Overflow用户
提问于 2017-04-21 08:17:59
回答 1查看 749关注 0票数 1

我正在尝试实现一种在智能手机热点上侦听客户端连接事件的方法。我看到,android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED不再是无价之宝。我该怎么做?我认为这是可能的,因为当我的客户端连接到智能手机热点时,智能手机会通知我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-02 15:07:01

您不能使用意图Action...You必须使用自定义方法,我建议您创建一个后台线程,不断检查/读取I.P表(/proc/net/arp)并更新您.下面是我使用的一个片段。

阅读i.p列表表

代码语言:javascript
复制
public ArrayList<String> getConnectedDevices() {
ArrayList<String> arrayList = new ArrayList();
try {
    BufferedReader bufferedReader = new BufferedReader(new FileReader("/proc/net/arp"));
    while (true) {
        String readLine = bufferedReader.readLine();
        if (readLine == null) {
            break;
        }
        String[] split = readLine.split(" +");
        if (split != null && split.length >= 4) {
            arrayList.add(split[0]);
        }
    }
} catch (Exception e) {
    e.printStackTrace();
}
return arrayList;
}

创建可运行的检查

代码语言:javascript
复制
class CheckHotSpotConnection implements Runnable {
private CheckHotSpotConnection() {
}

public void run() {
    int i = 0;
    while (discoverClient()) {
        i = getConnectedDevices().size();
        if (i > 1) {
            //client discovered

           //disable client discovery to end thread
        } else {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
}

启动线程

代码语言:javascript
复制
 new Thread(new CheckHotSpotConnection()).start();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43537451

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档