Reputation: 51
I am trying to create a WI-FI Direct network with say 3 tablet PCs. I want to run WiFi-Direct as background service, with one device set as autonomous GO. Could someone please tell me how can this be done in Android? Also someone please tell me how we can set dedicated SSID and passphrase so that any time new devices are added to this network, they can search for a specific ssid and passphrase for connection establishment during the application initiation ?
I am using Android API Level 18 for my development ...
Thanks in advance ...
Upvotes: 4
Views: 10065
Reputation: 588
This is how an autonomous Group Owner is created i.e. using the following code you can deliberately set a device in Wifi direct Network as a Group Owner
manager.createGroup(channel,new WifiP2pManager.ActionListener()
{
@Override
public void onSuccess()
{
Toast.makeText(WiFiDirectActivity.this, "Group Created",Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(int reason)
{}
});
You can use this code on any event like Button click etc.
Upvotes: 6
Reputation: 131
To create autonomous group you can just invoke createGroup()
method from your manager. In order to set ssid and passPhrase you must invoke the hidden methods of WifiP2pGroup class setPassphrase and setNetworkName.
To achieve that, you use java reflection. Try the following example.
Let us assume WifiP2pGroup
group your current object.
Method
setPassPhraseMethod=group.getClass().getMethod("setPassphrase", new Class[ {String.class});
and now you invoke the method:
setPassPhraseMethod.invoke(group, "yourNewPassPrhase");
hope it is helpful.
Upvotes: 2
Reputation: 349
Bluemoon10 was almost right. I can't comment yet because I need 50 reputation :/. The config.groupOwnerIntent ranges from 1-15 with 15 being the highest intent to be group owner. If 2 devices try to connect with both GO intents == 15, the connect call will fail. If there is a GO intent tie lower than 15, the devices agree on a tie breaker bit and will succeed. So if you want one device to be group owner, you have to make sure that it is the only one trying to be. You can do this with Service Discovery, i.e. if there is a service running set your GO intent to 15 on the device with the service and 1 on the connecting device. Only one device needs to call connect to initiate connection.
Link to Service Discovery tutorial: http://developer.android.com/training/connect-devices-wirelessly/nsd-wifi-direct.html
Upvotes: 2
Reputation: 89
Normally the Group Owner is decided by the WiFi Direct protocol. However you can force it's hand by, using the config class.
final WifiP2pConfig config = new WifiP2pConfig();
config.deviceAddress=myDeviceAddr;
config.wps.setup = WpsInfo.PBC;
config.groupOwnerIntent =15;
In this case I think I'm correct in saying that 15 mean least likely to become GO, you set this to zero, if you want that device to be the GO. Also this might be where you can set pin etc take a look at WpsInfo. this config info in then passed into your connect call.
mManager.connect(mChannel, config, new WifiP2pManager.ActionListener().
Hope this helps.
Upvotes: 0