Alternative to discovering peers with Wifi Direct as it requires both phones running WiFi Direct discovery

廉价感情. 提交于 2019-12-01 09:21:22

There is no way to achieve your goal using WiFiDirect. You need to turn on WiFiDirect (programmatically or manual) on all devices which are going to be connected.

But there is a way to reduce discovering process effort. You can use a service discovering instead of regular p2p connection.

It allows doing p2p discovering only on one device (client). A second device (server) is just waiting for a connection invite.

In one of our application, we had an issue: when a device does p2p discovering, a bandwidth of the network is extremely decreased what led to disconnect already connected devices.

Using a service discovering really helped us. You can use the code as an example.

The only alternative I was able to find is navigating to Wi-Fi Direct settings. On Android 6.0 device it can be achieved like this: Wi-Fi -> Settings (3 dots menu in the right top corner) -> Wi-Fi Direct. Most probably it starts the discovery process itself...

What I deducted is that the Wi-Fi Direct is not a standalone feature as e.g. Bluetooth. It is a part of Wi-Fi so it can't be turned on/off separately. The Wi-Fi P2P Network creation starts with Group Owner negotiation which can be performed only between Wi-Fi Direct capable devices. As the P2P Group is formed, it is available for Wi-Fi Legacy devices also (it works like a standard ad-hoc network, visible by all Wi-Fi capable devices).

So in order to create P2P Network (Group) you have to negotiate with other P2P devices which is only possible if you turn on Wi-Fi Direct.

Jiraiya

As you have noticed that both the device should be on the discovery mode. I am currently working on a project on WIFI-DIRECT , and yes it is very unreliable . You will also find it hard to discover after a connection and/or disconnecting . So what I have done is ,when the user is turning ON the device WIFI i am using a thread (background in a infinite loop) to run the discovery after every 8 seconds and updating the UI. This worked for me and user doesn't have to search continuously.

public class DiscoveryUpdater implements Runnable {
@Override
public void run() {
    while(true) {
        mManager.discoverPeers(mChannel, new WifiP2pManager.ActionListener() {

            @Override
            public void onSuccess() {
                Log.d("DiscoveryUpdater", "Successful in adding Discovery Request");
                mManager.requestPeers(mChannel,peerListListener);
            }

            @Override
            public void onFailure(int reasonCode) {
                Log.d("DiscoveryUpdater", "Failed in adding Discovery Request "+reasonCode);
            }
        });
        try {
            Thread.sleep(8000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
}

Hope it helps ( Remember to update your list , I have not shown that)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!