Android and WiFi Direct - Connectivity Issues

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(); } 
+4
source share
2 answers

I had devices 4.0 and 4.1, and, as far as I can tell, 4.0 had the ability to switch Wi-Fi Direct, where, as in 4.1, it is always on. The reason people don’t understand this is because Wi-Fi Direct on 4.0 required disabling regular Wi-Fi. Later, in 4.1, the inclusion of regular Wifi is what allows Wi-Fi Direct “always connected”.

So, the TL version; DR: Turn on regular WiFi if you cannot find the Wi-Fi Direct option.

Not 100% on this, but I hope this helps.

+5
source

Why aren't you using WiFi shoot? You just turn on Wi-Fi, and when you go into Wi-Fi shooting, it will automatically show you that WiFi direct is on. To send files, just hold the file and select "Send." The “WiFi Shoot” option will appear. This app will send it via WiFi directly.

-7
source

Source: https://habr.com/ru/post/1446107/


All Articles