android - 如何以编程方式获取热点(AP)中的连接设备数量 [Android]

标签 android android-wifi android-networking

正在开发一个需要显示热点详细信息的应用程序,包括连接到热点的设备数量

我试过这个但没有奏效,

private int countNumMac()
    {
        int macCount =0;
        BufferedReader br = null;
        try {
            br = new BufferedReader(new FileReader("/proc/net/arp"));
            String line;

            System.out.println(br.toString());
            while ((line = br.readLine()) != null) {

                String[] splitted = line.split(" +");
                System.out.println("splitted :"+splitted);

                if (splitted != null && splitted.length >= 4) {
                    // Basic sanity check
                    String mac = splitted[3];
                    if (mac.matches("..:..:..:..:..:..")) {
                        macCount++;
                    } 
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if(macCount == 0)
            return 0;
        else
            return macCount-1; 
    }

有没有其他方法可以计算连接到热点的设备数量..

最佳答案

您输入的代码需要root权限
看看这个库。我希望它能解决你的问题
https://github.com/nickrussler/Android-Wifi-Hotspot-Manager-Class

关于android - 如何以编程方式获取热点(AP)中的连接设备数量 [Android],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17849395/

相关文章:

java - 网络监听器 Android

android - rndis0 设备是如何创建的

android - 如何在 android 中通过 Url 设置布局的背景图片?

android-studio - Android 模拟器 : wifi connected, 没有互联网

java - 如果 wifi 名称匹配,Android 以编程方式连接到 Wifi

android - Android 9.0(PIE)如何获取WIFI SSID?

php - Android 无法正确连接 MySQL 数据库

Android:错误:不能从静态上下文引用非静态类型变量 T

android - 如何将带有标记的 map 添加到android中的适配器项目?

Android 动画旋转