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);
}
});