I try to connect several devices to the group owner, which I manually select
I want peers to connect to the group owner manually when they find it
I have 3 phones (without emulators), each has a “Create Group” button with this click handler
public void createWifiGroup(View view) {
mManager.createGroup(mChannel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
mManager.requestGroupInfo(mChannel,new MyGroupInfoListener(MainActivity.this));
}
@Override
public void onFailure(int reason) {
}
});
}
As you can see, I do requestGroupInfoand pass it a listener that prints the following line in the logs:
groupFormed: true isGroupOwner: true groupOwnerAddress: /192.168.49.1
So, I suppose that succeeded
I also have a class MyPeerListenerthat calls BroadCastReceiverwhen an intent is accepted WIFI_P2P_PEERS_CHANGED_ACTION.
MyPeerListener will go through peers and connect if he finds the group owner
@Override
public void onPeersAvailable(WifiP2pDeviceList wifiP2pDeviceList) {
this.wifiP2pDeviceList = wifiP2pDeviceList;
Iterator<WifiP2pDevice> deviceListIterator = wifiP2pDeviceList.getDeviceList().iterator();
boolean foundGroup = false;
while (deviceListIterator.hasNext()) {
final WifiP2pDevice device = deviceListIterator.next();
if (!foundGroup && device.isGroupOwner() && !MainActivity.connected) {
foundGroup = true;
final WifiP2pConfig config = new WifiP2pConfig();
config.groupOwnerIntent = 0;
config.deviceAddress = device.deviceAddress;
MainActivity.mManager.connect(MainActivity.mChannel, config, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
Toast toast = Toast.makeText(receiver.mActivity, "connect success", Toast.LENGTH_SHORT);
toast.show();
MainActivity.connected = true;
MainActivity.mManager.requestGroupInfo(MainActivity.mChannel, new MyGroupInfoListener(receiver.mActivity));
MainActivity.mManager.requestConnectionInfo(MainActivity.mChannel, new MyConnectionInfoListener(receiver));
}
@Override
public void onFailure(int reason) {
Toast toast = Toast.makeText(receiver.mActivity, "connect fail, reason: " + reason, Toast.LENGTH_LONG);
toast.show();
}
});
}
ListView list = (ListView) receiver.mActivity.findViewById(R.id.device_list_view);
list.setAdapter(new DeviceListViewAdapter(this, receiver.mActivity));
}
}
}
( , )
connect success Toast, requestConnectionInfo
groupFormed: false isGroupOwner: false groupOwnerAddress: null
requestGroupInfo :
group is null
80% . IP 192.168.49.1. , "" .
, - null, destination host unreachable. , .
? , , null?