WifiDirect.discoverPeers is often BUSY or ERROR
manager.discoverPeers(channel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
Toast.makeText(WiFiDirectActivity.this, "Discovery Initiated",
Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(int reasonCode) {
Toast.makeText(WiFiDirectActivity.this, "Discovery Failed : " + reasonCode,
Toast.LENGTH_SHORT).show();
}
});
Sometimes it works great, other times it will spend more than an hour and a half making mistakes with every button press to discover peers. I will get BUSY (2) and ERROR (0) comes out at about the same rate.
I haven't been able to find out WHY I ever get these results, and if I just need to live with them. My tablets are Nexus 7 running Android 4.3.
Questions:
Can other devices be expected to be similarly flaky? Is there something I can do to improve my behavior? Is there anything I can do to find out more details than "BUSY" or "ERROR"? LOGCAT doesn't seem to help ...
Edit: I meant that I have two tablets, both of which are Nexus 7s.
source to share
You can put the method discoverPeers
in a recursion loop.
private void discoverPeersTillSuccess() {
manager.discoverPeers(channel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
// remaining code
}
@Override
public void onFailure(int reasonCode) {
discoverPeersTillSuccess();
}
}
}
This will continue on trying discoverPeers
until success returns.
source to share