Check whether android wifip2p connection was successful?

六眼飞鱼酱① 提交于 2019-12-01 21:50:52

The class needs to implement ConnectionInfoListener. And in the function onConnectionInfoAvailable(final WifiP2pInfo info) you can check if a successful connection has been established or not. The info argument of type WifiP2pInfo contains the information about the connection. It contains a boolean called groupFormed which indicates if a p2p group has been successfully formed. You can also retrieve from it if the device is groupOwner and the IP of the groupOwner, etc.

@Override
    public void onConnectionInfoAvailable(final WifiP2pInfo info) {

        // After the group negotiation, we check if this device 
        // is acting as group owner

        if (info.groupFormed && !info.isGroupOwner) {

            // Do whatever you want the group owner to do

        } else if (info.groupFormed) {
            // The device now act as the slave device, 
            // and the other connected device is group owner
    }

Google provides a very good demo app that uses WiFi Direct to send an image between 2 devices. Check its implementation and try to build on top of it. Link: http://developer.android.com/guide/topics/connectivity/wifip2p.html

Hope this helps. Let me know if you have any questions.

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