组播和即时应用

时间:2019-01-13 12:19:41

标签: java android permissions multicast android-instant-apps

通常,我可以使用MulticastSocketnetwork service discovery通过Wi-Fi网络查找服务器

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));
    ...
}

它工作正常,但是我不能在Instant App模块内使用这些方法,因为它需要不允许的 ACCESS_WIFI_STATE 权限。

知道即时应用程序允许 ACCESS_NETWORK_STATE INTERNET 权限,有什么方法可以找到本地服务器IP,从而避免此错误?

java.net.BindException: bind failed: EACCES (Permission denied)

available permissions是:

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

0 个答案:

没有答案