Search code examples
androidconnectionwifi-direct

Monitoring incoming wifi p2p connection using wifi direct


I'm looking for a way to monitor,on group owner side, any new incoming WiFi p2p connection using wifi direct, whenever a group already exists. I mean, let suppose we have a group which consists of two devices, D1 (as group owner) and D2 (as client). A third device D3 wants to join the existing group as client. So, it (D3) calls connect() method "towards" D1. Now D1 should add D3. Which is the notification which tells me that everything has been correctly done (on group owner side)? I know, for sure, that WIFI_P2P_CONNECTION_CHANGED_ACTION is used in order to notify that a new connection has been established for the first time .Is it valid for every client which wants to join the group after it has been created?

Note: I'm interested in knowing what happens on group owner side, not on client.

Thanks in advance for your time.


Solution

  • Yes. Everytime when a client connect to a GO, the GO will receive WIFI_P2P_CONNECTION_CHANGED_ACTION.

    Actually, I register broadcastReceiver with filter like this, and monitor my D1 (as a Group Owner)

    IntentFilter filter = new IntentFilter();
    filter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
    filter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
    filter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
    filter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
    

    When the first client coming, the sequence of triggered ACTION the GO received is

    WIFI_P2P_THIS_DEVICE_CHANGED_ACTION
    WIFI_P2P_PEERS_CHANGED_ACTION   
    WIFI_P2P_CONNECTION_CHANGED_ACTION
    

    When the second one coming, the sequence is

    WIFI_P2P_PEERS_CHANGED_ACTION   
    WIFI_P2P_CONNECTION_CHANGED_ACTION