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

前端 未结 6 2115
余生分开走
余生分开走 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 17:01

    I was struggling all night to figure out a way to retrieve WiFi Direct mac address instead, since my requirements were drafted around the assumption that it's feasible.

    It's kind of round about, you create a single device group and get the owner and the device address along with it.

    Here's the code,

        final WifiP2pManager p2pManager = (WifiP2pManager) getSystemService(WIFI_P2P_SERVICE);
        final WifiP2pManager.Channel channel = p2pManager.initialize(this, getMainLooper(), null);
    
        p2pManager.createGroup(channel, new WifiP2pManager.ActionListener() {
            @Override
            public void onSuccess() {
                p2pManager.requestGroupInfo(channel, new WifiP2pManager.GroupInfoListener() {
                    @Override
                    public void onGroupInfoAvailable(WifiP2pGroup wifiP2pGroup) {
                        Log.i("", wifiP2pGroup.getOwner().deviceAddress);
    
                        // Following removal necessary to not have the manager busy for other stuff, subsequently
                        p2pManager.removeGroup(channel, new WifiP2pManager.ActionListener() {
                            @Override
                            public void onSuccess() {
                                Log.i("", "Removed");
                            }
    
                            @Override
                            public void onFailure(int i) {
                                Log.i("", "Failed " + i);
                            }
                        });
                    }
                });
            }
    
            @Override
            public void onFailure(int i) {
                Log.i("", String.valueOf(i));
            }
        });
    

提交回复
热议问题