2

I am using WiFiDirect to connect my android device to another device using WiFiDirect.

I have the following method to get the host IP address which works great when device is not the group owner.

public String getDestinationDeviceIpAddress(WifiP2pInfo wifiP2pInfo) {
    String destinationAddress;
    if (wifiP2pInfo.isGroupOwner) {
        destinationAddress = // How to get the address here ???

    } else {
        // This works great !
        destinationAddress = wifiP2pInfo.groupOwnerAddress.getHostAddress();
    }
    return destinationAddress;
}

Question:
How do I get the peer's address for the case where wifiP2pInfo.isGroupOwner is true? In other words, how to get the peer's address when the android device is the Group Owner(GO)?

Android sdk version:
Targeting android sdk version 28 and above

AdeleGoldberg
  • 1,289
  • 3
  • 12
  • 28
  • I had the same problem and ended up doing sth like this answer, which just connects to the group owner and the GO gets the ip from the established connection: https://stackoverflow.com/a/14525688/4288004 That is the least hacky way I could find instead of trying to find the ip yourself and sending it (which is hard, because you have to go through the network interfaces etc) or relying on the arp cache of the mac address, which could break depending on the behaviour of the cache and future changes to this very low level api. – xuiqzy Mar 29 '20 at 13:36
  • Is there any solution of that? I am trying to send one file to multiple connections but the problem is I want to make the group owner to the sender and it creates group owner as per device. – Raman Joshi Oct 29 '20 at 08:20

0 Answers0