WiFi Direct on Android not working properly
Asked Answered
S

1

5

I am trying to develop an app using wifi direct in android Jelly Bean 4.1.1. If p2p is enabled I immedialtely call

mManager.discoverPeers(mChannel, actionListener);

After that I am getting a call back to the

onPeersAvailable(WifiP2pDeviceList)

I am testing with 2 Samsung(Google) Nexus device and wifi direct is turned on on both. But this call back is returning an empty list of peers. But for instance if I click on the Search Peers button on the default wifi direct interface immedialtely the second device fires the

WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION

and this inturn calls

onPeersAvailable(WifiP2pDeviceList peers)

as I am requesting for peers for that event using

mManager.requestPeers(mChannel, WifiDirectService.this);

This time I will be able to see the peers. I am seeing this for a number of times.

What could be the possible reason? Thanks

Strangle answered 4/10, 2012 at 14:41 Comment(0)
I
1

You should use the Discovering peermethod:

manager.discoverPeers(channel, new WifiP2pManager.ActionListener() {
    @Override
    public void onSuccess() {
        ...
    }

    @Override
    public void onFailure(int reasonCode) {
        ...
    }
});

If the discovery process succeeds and detects peers, the system broadcasts the WIFI_P2P_PEERS_CHANGED_ACTION intent, which you can listen for in a broadcast receiver to obtain a list of peers. When your application receives the WIFI_P2P_PEERS_CHANGED_ACTION intent, you can request a list of the discovered peers with requestPeers().

For the full example, please check: http://developer.android.com/guide/topics/connectivity/wifip2p.html#discovering

Inversely answered 4/10, 2012 at 14:46 Comment(5)
What are you doing then on success ?Inversely
Please, read this tutorial from the Android official website, maybe you are doing something wrong, the example is really easy to understand. developer.android.com/guide/topics/connectivity/…Inversely
I am stuck on similar problem now but I can't obtain the list of peers at all. I call 'discoverPeers(..)' on ' WifiP2pManager' instance and I print some message to the log 'onSuccess()' and 'onFailure()'. He always successfully detects peers but it seems like system is not broadcasting the 'WIFI_P2P_PEERS_CHANGED_ACTION'. I do register the broadcast receiver and I do call 'requestPeers(..)'.Phene
Were you able to fix it?Lulu
@CommonsWare can help with any solution ?Jubal

© 2022 - 2024 — McMap. All rights reserved.