So, I’ve been working with Wi-Fi Direct for quite some time, and throughout this I have been bothered by connection issues. Since upgrading to 4.1, where there is no longer a hard button to turn Wi-Fi Direct on and off, I seem to always have inconsistencies with the connection. For my purposes, I don’t need to find peers, just connect to peers from the stored addresses of devices from earlier interactions. Sometimes devices will connect immediately, while the second device will not receive an invitation, and another time the first device will get stuck trying to send an invitation for an indefinite period. Below is my connection code, it is pretty bare, so I'm not sure what is wrong. Any help would be appreciated! Thank you very much.
WifiP2pConfig config = new WifiP2pConfig(); SlideMenuItem item = sideMenu.getItem(itemId); config.deviceAddress = item.label; config.wps.setup = WpsInfo.PBC; if (progressDialog != null && progressDialog.isShowing()) { progressDialog.dismiss(); } progressDialog = ProgressDialog.show(mContext, "Press back to cancel", "Connecting to :" + item.label, true, true); manager.connect(channel, config, new ActionListener() { @Override public void onSuccess() { // WiFiDirectBroadcastReceiver will notify us. Ignore for now. } @Override public void onFailure(int reason) { Toast.makeText(mContext, "Connect failed. Retry.", Toast.LENGTH_SHORT).show(); } }); @Override public void onConnectionInfoAvailable(WifiP2pInfo arg0) { // TODO Auto-generated method stub if (progressDialog != null && progressDialog.isShowing()) { progressDialog.dismiss(); } Toast.makeText(this, "Succesfully connected.", Toast.LENGTH_SHORT).show(); }
source share