我正在尝试使用Android自己的Wi-Fi直接接口将设备直接与另一台设备配对。
但是我在接受来自类似设备的传入群组邀请时遇到问题。
从客户端我设法得到这个错误:
09-16 13:42:07.547: E/WifiP2pService(511): Unhandled message { what=147487 when=-1ms obj=network: null
09-16 13:42:07.547: E/WifiP2pService(511): isGO: false
09-16 13:42:07.547: E/WifiP2pService(511): GO: Device:
09-16 13:42:07.547: E/WifiP2pService(511): deviceAddress: *CENSORED*
09-16 13:42:07.547: E/WifiP2pService(511): primary type: null
09-16 13:42:07.547: E/WifiP2pService(511): secondary type: null
09-16 13:42:07.547: E/WifiP2pService(511): wps: 0
09-16 13:42:07.547: E/WifiP2pService(511): grpcapab: 0
09-16 13:42:07.547: E/WifiP2pService(511): devcapab: 0
09-16 13:42:07.547: E/WifiP2pService(511): status: 4
09-16 13:42:07.547: E/WifiP2pService(511): wfdInfo: null
09-16 13:42:07.547: E/WifiP2pService(511): Client: Device:
09-16 13:42:07.547: E/WifiP2pService(511): deviceAddress: *CENSORED*
09-16 13:42:07.547: E/WifiP2pService(511): primary type: null
09-16 13:42:07.547: E/WifiP2pService(511): secondary type: null
09-16 13:42:07.547: E/WifiP2pService(511): wps: 0
09-16 13:42:07.547: E/WifiP2pService(511): grpcapab: 0
09-16 13:42:07.547: E/WifiP2pService(511): devcapab: 0
09-16 13:42:07.547: E/WifiP2pService(511): status: 4
09-16 13:42:07.547: E/WifiP2pService(511): wfdInfo: null
09-16 13:42:07.547: E/WifiP2pService(511): interface: null
09-16 13:42:07.547: E/WifiP2pService(511): networkId: -2 }
GO(组所有者)使用以下代码连接:
WifiP2pConfig config = new WifiP2pConfig();
config.deviceAddress = device.deviceAddress;
config.groupOwnerIntent = 15;
config.wps.setup = WpsInfo.PBC;
mManager.connect(mChannel, config, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
new FetchDeviceInfo().execute(device);
}
@Override
public void onFailure(int reason) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "Failure to connect: " + reason, Toast.LENGTH_SHORT).show();
}
});
执行Asynctask只是为了获取客户端IP地址。
答案 0 :(得分:0)
如果两个设备都想成为组所有者(config.groupOwnerIntent == 15),则协商组所有者的协议将失败。如果GO意图相同并且会成功,那么任何下面都有一个决胜局位。
我连接两台设备(使用您的代码)的方式如下:
WifiP2pConfig config = new WifiP2pConfig();
config.deviceAddress = device.deviceAddress;
config.wps.setup = WpsInfo.PBC;
Random r = new Random();
config.groupOwnerIntent = r.nextInt(14);
mManager.connect(mChannel, config, new WifiP2pManager.ActionListener() {
...