我有一个执行WiFi P2P发现的代码,它会向用户展示附近的设备,并让用户选择要连接的设备。发现功能正常,但当我尝试实际连接所选设备时,系统调用ActionListener.onFailure函数并传递"内部错误"的原因代码。
以下是启动连接的代码:
当出现此错误时,设备不属于任何组,这种情况发生在设备(Nexus 4&Nexus 7)中的任何一个是发起者时。有什么想法可能是问题?
以下是启动连接的代码:
public void connectToDevice(WifiP2pDevice device) {
Log.i(TAG, "Initiating connection to " + device.deviceAddress);
stopScan();
WifiP2pConfig config = new WifiP2pConfig();
config.deviceAddress = device.deviceAddress;
config.wps.setup = WpsInfo.PBC;
// Since we wish to send a friend request, it will be easier if
// we'll end up as a client because we will have the group owner's
// address immediately.
config.groupOwnerIntent = 0;
mP2pManager.connect(mChannel, config, mConnectionListener);
}
mConnectionListener
如下所示:
protected ActionListener mConnectionListener = new ActionListener() {
@Override
public void onSuccess() {
Log.i(TAG, "Conection initiated successfuly");
}
@Override
public void onFailure(int reason) {
String reasonString = reason(reason);
Log.e(TAG, "Error while connecting to Wifi peer: " + reasonString);
}
};
当出现此错误时,设备不属于任何组,这种情况发生在设备(Nexus 4&Nexus 7)中的任何一个是发起者时。有什么想法可能是问题?