3

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
Greelings
  • 4,964
  • 7
  • 34
  • 70
  • Have you tried some other methods like from https://stackoverflow.com/questions/4464207/android-find-a-server-in-the-network? However, if they all use a disallowed permission, then it will not be possible. – TWL Jan 14 '19 at 18:36
  • Thank you for you help. Unfortunately, these methods do not work with IPv6 addresses. – Greelings Jan 15 '19 at 08:06

0 Answers0