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.
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.
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();
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With