Wi-Fi Direct and “normal” Wi-Fi - Different MAC?

前端 未结 6 2097
余生分开走
余生分开走 2021-01-02 16:25

I\'m currently trying to connect two phones which know each other\'s MAC address via Wi-Fi Direct, and stumbled upon the following problem: The MAC address, which I receive

6条回答
  •  死守一世寂寞
    2021-01-02 16:47

    You can get WiFi direct address using next code:

    public String getWFDMacAddress(){
    try {
        List interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface ntwInterface : interfaces) {
    
            if (ntwInterface.getName().equalsIgnoreCase("p2p0")) {
                byte[] byteMac = ntwInterface.getHardwareAddress();
                if (byteMac==null){
                    return null;
                }
                StringBuilder strBuilder = new StringBuilder();
                for (int i=0; i0){
                    strBuilder.deleteCharAt(strBuilder.length()-1);
                }
    
                return strBuilder.toString();
            }
    
        }
    } catch (Exception e) {
        Log.d(TAG, e.getMessage());
    }
    return null;
    

    }

提交回复
热议问题