我有一个执行 Wifi P2p 发现的代码,将附近的设备呈现给用户,让他选择他想要连接的设备。
发现按预期工作,但是当我尝试实际连接到所选设备时,系统调用ActionListener.onFailure
并传递“内部错误”的原因代码。
这是启动连接的代码:
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)是发起方时会发生这种情况。
任何想法可能是什么问题?