获取已经连接热点的设备

来源:互联网 发布:数据库日志截断收缩 编辑:程序博客网 时间:2024/05/10 00:42

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

我用来关闭二维码了

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

百度了一下午........就还是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();    }


0 0
原创粉丝点击