Reputation: 1259
I am using WifiP2pManager class to initiate the discovery of Peers as referred here: http://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html
Part of the code goes as follows:
//Activity Class
@Override
protected void onCreate(Bundle savedInstanceState) {
...
mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
mChannel = mManager.initialize(this, getMainLooper(), null);
//Separate class here
mReceiver = new WiFiDirectBroadcastReceiver(mManager, mChannel, this);
//register the events to filter on to perform the broadcast receiver
mIntentFilter = new IntentFilter();
mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
mManager.discoverPeers(mChannel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
myTextView.setText("Success discovery");
}
@Override
public void onFailure(int reasonCode) {
myTextView.setText("Discovery errorcode:" + String.valueOf(reasonCode));
}
});
}
Happens that I get the onSuccess
call in my phone (JellyBean based), but a Lenovo A2107A Tablet used for testing running Android 4.1.2 IceCream sandwich just get onFailure
where reasonCode equals 2 (Busy):
http://developer.android.com/reference/android/net/wifi/p2p/WifiP2pManager.ActionListener.html
I noticed that in the Wifi Settings of the phone the WifiDirect discovery list option shows up, but in the tablet there is no option to do this, although the OS version 4.x supposedly supports it, programmatically at least (I tested ShareIt App and the tablet can transfer files through WiFi).
A similar question has been made here: Why do I always get BUSY when using WifiP2pManager? but with no accepted answer.
Is there anything I can do to avoid the always busy state while using this API method on the Tablet?. Thanks!
Upvotes: 2
Views: 4469
Reputation: 11
Please make sure the Wifi is enabled before discoveryPeers is called. I got the BUSY when the Wifi is disabled; and success when Wifi is enabled.
Upvotes: 1
Reputation: 1259
Apparently the Lenovo A2107A tablet returning "Busy" state after calling the WifiP2pManager instance on its discoveryPeers
method, doesn't support WiFi Direct/WiFi P2P, in fact there is no option to lookup for P2P peers on it, hence returning the statusCode 2 Busy status in the onFailure
callback, even running Android 4.1.2 that in theory does support WifiDirect which is a bit strange.
A couple of helpful projects to understand better the inner workings of this technology are here:
https://github.com/ahmontero/wifi-direct-demo
https://github.com/mayfourth/WiFi-Direct-File-Transfer
Upvotes: 1