Reputation: 2216
I have an Wifi Direct Android Application which will run on two Phones.
When phone1
connects to phone2
, I want phone1
to act as a client
and phone2
to act as a server
.
I used this code:
if (info.groupFormed && info.isGroupOwner) {
// start the server thread
} else if (info.groupFormed) {
// start the client thread
}
But the problem is that , sometimes phone1
which has initiated the connection and I want it to act as a client , it sometimes acts as a GroupOwner
, and the server thread is started on the client phone.
I want to make sure that phone2
always act as a GroupOwner
and a server
.
Upvotes: 8
Views: 9419
Reputation: 2044
Well, what you can do is:
@Override
public void connect(final WifiP2pDevice device) {
//obtain a peer from the WifiP2pDeviceList
WifiP2pConfig config = new WifiP2pConfig();
config.deviceAddress = device.deviceAddress;
config.wps.setup = WpsInfo.PBC;
config.groupOwnerIntent = 15; // I want this device to become the owner
mManager.connect(mChannel, config, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
//success logic
Log.d(P2P, "connected to device " + device.deviceName);
}
@Override
public void onFailure(int reason) {
//failure logic
Log.d(P2P, "unable to establish connection to device " + device.deviceName);
}
});
}
Note the config.groupOwnerIntent = 15;
line. This tells WifiP2pConfig that we the device stating the connection is more likely to become a GroupOwner.
Doc here
Hope it helps.
Upvotes: 5
Reputation: 2216
To set a peer as a client , not a GroupOWner
eachtime , we have to assign:
config.groupOwnerIntent = 0;
Upvotes: 13