【问题标题】:Get the Name of connected device with Hotspot使用 Hotspot 获取连接设备的名称
【发布时间】:2017-05-11 09:17:15
【问题描述】:

如何获取从热点(服务器)连接的设备名称?

一个热点连接多台设备却无法获取连接设备的名称,如何获取?

我可以很容易地获得 IP 地址,但如何获得名称?

【问题讨论】:

    标签: android file sockets share


    【解决方案1】:

    下面的方法可以,但是,这是检测4.0及以上版本;无法找到与热点连接的2.2或2.3版本的设备。

    public void getClientList() {
    int macCount = 0;
    BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader("/proc/net/arp"));
        String line;
        while ((line = br.readLine()) != null) {
            String[] splitted = line.split(" +");
            if (splitted != null ) {
                // Basic sanity check
                String mac = splitted[3];
                System.out.println("Mac : Outside If "+ mac );
                if (mac.matches("..:..:..:..:..:..")) {
                    macCount++;
                   /* ClientList.add("Client(" + macCount + ")");
                    IpAddr.add(splitted[0]);
                    HWAddr.add(splitted[3]);
                    Device.add(splitted[5]);*/
                    System.out.println("Mac : "+ mac + " IP Address : "+splitted[0] );
                    System.out.println("Mac_Count  " + macCount + " MAC_ADDRESS  "+ mac);
                Toast.makeText(
                        getApplicationContext(),
                        "Mac_Count  " + macCount + "   MAC_ADDRESS  "
                                + mac, Toast.LENGTH_SHORT).show();
    
                }
               /* for (int i = 0; i < splitted.length; i++)
                    System.out.println("Addressssssss     "+ splitted[i]);*/
    
            }
        }
    } catch(Exception e) {
    
    }               
    }
    

    ==>检查这里:

    检查requestPeers 的WifiP2pManager

    根据文档,它寻找PeerListListener,它返回WifiP2pDeviceList 携带WifiP2pDevice 列表,其中携带deviceAddress、deviceName、primaryDeviceType、secondaryDeviceType、status 和其他属性。

    【讨论】:

    • 这只会给出主机名或IP地址。
    • @jaimin,无法获取设备名称?
    • @ShubhamMaheshwari 请编辑答案。检查底部。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 1970-01-01
    • 2018-02-05
    • 1970-01-01
    相关资源
    最近更新 更多