获取已经连接热点的设备
发布日期:2021-05-07 18:58:17 浏览次数:29 分类:原创文章

本文共 2103 字,大约阅读时间需要 7 分钟。

这个用途说出来你们可能不信....

我用来关闭二维码了

扫描完成之后关闭......

百度了一下午........就还是google好啊......

    public void getListOfConnectedDevice() {        Thread thread = new Thread(new Runnable() {            @Override            public void run() {                sendMessageCheckConnect();                BufferedReader br = null;                boolean isFirstLine = true;                try {                    br = new BufferedReader(new FileReader("/proc/net/arp"));                    String line;                    while ((line = br.readLine()) != null) {                        if (isFirstLine) {                            isFirstLine = false;                            continue;                        }                        String[] splitted = line.split(" +");                        if (splitted != null && splitted.length >= 4) {                            String ipAddress = splitted[0];                            String macAddress = splitted[3];                            boolean isReachable = InetAddress.getByName(                                    splitted[0]).isReachable(500);  // this is network call so we cant do that on UI thread, so i take background thread.                            if (isReachable) {                                Log.d("Device Information", ipAddress + " : "                                        + macAddress);                                //如果已经有一个连接的了 那么 就关闭当前页面 并且                                mHandler.removeCallbacksAndMessages(null);                                finish();                            }else {                                Log.d("Device Information", ipAddress + " : "                                        + macAddress);                            }                        }                    }                } catch (Exception e) {                    e.printStackTrace();                } finally {                    try {                        br.close();                    } catch (IOException e) {                        e.printStackTrace();                    }                }            }        });        thread.start();    }


上一篇:viewpager的setOffscreenPageLimit方法有什么作用
下一篇:简单的实现自定义广播(Broadcast)机制

发表评论

最新留言

不错!
[***.144.177.141]2025年03月21日 02时44分25秒