Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WifiP2pDevice status stays on INVITED after Wifi Direct Invitation

I am programming a Wifi Direct game, but have run into a problem with the WifiP2pDevice Status when one user declines the invitation to join the connection.

  1. Phone A initiates connection to Phone B
  2. Phone B status becomes INVITED (as displayed on Phone A)
  3. Phone B decline invitation from Phone A
  4. Phone B status is still INVITED (as displayed on Phone A)

Shouldn't the status be shifted back to AVAILABLE as displayed on Phone A? I have refreshed the list of Available devices, but the status remains unchanged. even if I restart the app, it still shows the status of Phone B as invited?

Is this supposed to happen based on the API of WifiDirect? or am I missing something?

Edit: More Information

In the BroadcastReciever, when the intent is WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION, then the manager requests the peers using a Fragment that implements a PeerListListener, which just prints a list of available devices and information (including status) of those devices. So when Phone A sends an invitation with manager.connect() it changes the status to INVITED. But if Phone B declines, the status remains as INVITED. And those statuses are triggered on a notifyDataSetChanged(). It is not so much a question about code, but how wifi direct determines and changes statuses of the devices. But I can provide code if needed.

like image 917
The4thIceman Avatar asked Feb 26 '14 19:02

The4thIceman


1 Answers

You can cancel the connection if the status is "Invited"

 if (fragment.getDevice().status == WifiP2pDevice.AVAILABLE
                || fragment.getDevice().status == WifiP2pDevice.INVITED) {

            manager.cancelConnect(channel, new ActionListener() {

                @Override
                public void onSuccess() {
                    Toast.makeText(WiFiDirectActivity.this, "Aborting connection",
                            Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onFailure(int reasonCode) {
                    Toast.makeText(WiFiDirectActivity.this,
                            "Connect abort request failed. Reason Code: " + reasonCode,
                            Toast.LENGTH_SHORT).show();
                }
            });
        }
like image 126
Pay Avatar answered Sep 19 '22 06:09

Pay