Usually I can use a MulticastSocket or a network service discovery to find a server over a Wi-Fi network
try (MulticastSocket multicastSocket = new MulticastSocket(Network.DISCOVERY_PORT)) {
multicastSocket.setNetworkInterface(Network.getWifiInterface());
multicastSocket.setSoTimeout((int) (3 * DateUtils.SECOND_IN_MILLIS));
multicastSocket.joinGroup(InetAddress.getByName(Network.DISCOVERY_IP));
...
}
It works fine, however I could not use these methods inside an Instant App module, because it needs the ACCESS_WIFI_STATE permission that is not allowed.
Knowing that the instant apps allow the ACCESS_NETWORK_STATE and INTERNET permission, is there any way to find a local server IP, avoiding this error?
java.net.BindException: bind failed: EACCES (Permission denied)
The available permissions are :
ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION ACCESS_NETWORK_STATE BILLING – Deprecated as of Play Billing Library 1.0. CAMERA INSTANT_APP_FOREGROUND_SERVICE – Only in Android 8.0 (API level 26) and higher. INTERNET READ_PHONE_NUMBERS – Only in Android 8.0 (API level 26) and higher. RECORD_AUDIO VIBRATE WAKE_LOCK