### UI/UX popups
Several years ago when I was working on RightMesh, it used to be possbile to startup a Wi-Fi direct hotspot on Android, use the advertising service or bluetooth to share the credentials and have another phone discover these credentials and connect automatically with no dialogs.
For instance, you could do something like this, which would startup a group and then advertise it via Wi-Fi broadcasts:
```
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void startGroup(View v) {
wifiP2pManager.createGroup(channel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
Log.d(TAG, "SUCCESS STARTING GROUP");
groupStarted = true;
wifiP2pManager.requestGroupInfo(channel, new WifiP2pManager.GroupInfoListener() {
@Override
public void onGroupInfoAvailable(WifiP2pGroup group) {
if(group == null) {
Log.d(TAG, "GROUP IS NULL");
} else {
Log.d(TAG, "MY GROUP: " + group.getNetworkName() + " "
+ group.getPassphrase() + " "
+ group.getInterface() + " "
+ group.getOwner().deviceAddress);
//advertise service record
Map<String,String> record = new HashMap<>();
record.put("name", group.getNetworkName());
record.put("pass", group.getPassphrase());
record.put("mac", group.getOwner().deviceAddress);
WifiP2pDnsSdServiceInfo serviceInfo = WifiP2pDnsSdServiceInfo.newInstance
("_wifid", "_connection._autoconf", record);
wifiP2pManager.addLocalService(channel, serviceInfo, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
Log.d(TAG, "Success Advertising local service");
}
@Override
public void onFailure(int i) {
Log.d(TAG, "Fail Advertising local service");
}
});
}
}
});
}
}
```
And then another device could discover and connect to the hotspot with something like this
```
WifiP2pManager.DnsSdTxtRecordListener txtListener = new WifiP2pManager.DnsSdTxtRecordListener() {
@Override
public void onDnsSdTxtRecordAvailable(String fullDomain, Map record, WifiP2pDevice device) {
Log.d(TAG, "DnsSdTxtRecord available -" + record.toString());
WifiNetworkSpecifier wifiNetworkSpecifier = new WifiNetworkSpecifier.Builder()
.setSsid(record.get("SSID").toString())
.setWpa2Passphrase(record.get("pass").toString())
.build();
NetworkRequest request = new NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.setNetworkSpecifier(wifiNetworkSpecifier)
.build();
connectivityManager.requestNetwork(request, null);
}
};
```
Which would just allow them to connect to each other more or less without user intervention. Now with all of the security improvements on Android, you can either get a popup on the client side asking if you'd like to connect to this new network, or a popup on the hotspot side asking if you'd like to accept the connection.
### Difficulty being both a hotspot and client
It also used to be possible to simulteanously act as a Wi-Fi direct hotspot and also be a client. When you run in hotspot mode, a second virtual wifi interface is created and named something like `p2p`. When you are acting in client mode, all you had to do was bind the process to the `wlan` interface and you could reach the hotspot you were connected to. It seems like this is no longer possible with ipv4.
```
@Override
public void onAvailable(@NonNull Network network) {
super.onAvailable(network);
Log.d(TAG,"Network available: " + network);
connectivityManager.bindProcessToNetwork(network);
hotspotAddress = InetAddress.getByName("192.168.49.1");
socket = new DatagramSocket();
byte[] buffer = "test".getBytes();
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, hotspotAddress, SOME_PORT);
socket.send(packet);
}
```
Its posssible now only with ipv6 by making a connection originating at the hotspot side towards the wifi client - so still possible, just extra annoying.
Check out [https://github.com/compscidr/wifi-direct-test](https://github.com/compscidr/wifi-direct-test) for some of my wifi-direct connectivity experiments in more detail.