I have developed a WiFi Direct Application and I used this code to differentiate between a groupOwner and other device. But groupOwner is always made randomly. I want to make sure that connecting device acts like a groupOwner every time a connection is made. My code :
if (info.groupFormed && info.isGroupOwner) {
// GroupOwner
} else if (info.groupFormed) {
}
If your goal is to make the device, which is advertising a service, also the group owner, then on your WifiP2pManager instance call createGroup in the onSuccess callback of addLocalService
WifiP2pManager manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
WifiP2pManager.Channel channel = serverManager.initialize(this, getMainLooper(), null);
HashMap<String, String> record = new HashMap<String, String>();
WifiP2pServiceInfo serviceInfo = WifiP2pDnsSdServiceInfo.newInstance("_hello", "_world._tcp", record);
//remove legacy group
manager.removeGroup(channel, null);
//advertise your service
manager.addLocalService(channel, serviceInfo, new WifiP2pManager.ActionListener() {
@Override
public void onFailure(int reason) {
}
@Override
public void onSuccess() {
//create group, making this device the owner of the group
manager.createGroup(channel, null);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With