Android Question no udp broadcast address is returned

lewi

Member
Licensed User
Longtime User
Hi all,

in my project i'm using this snippet to get udp broadcast address
udp broadcast:
'Returns the UDP broadcast address.
'Returns an empty string if not available.
Sub GetBroadcastAddress As String
   Dim niIterator As JavaObject
   niIterator = niIterator.InitializeStatic("java.net.NetworkInterface").RunMethod("getNetworkInterfaces", Null)
   Do While niIterator.RunMethod("hasMoreElements", Null)
     Dim ni As JavaObject = niIterator.RunMethod("nextElement", Null)
     If ni.RunMethod("isLoopback", Null) = False Then
       Dim addresses As List = ni.RunMethod("getInterfaceAddresses", Null)
       For Each ia As JavaObject In addresses
         Dim broadcast As Object = ia.RunMethod("getBroadcast", Null)
         If broadcast <> Null Then
           Dim b As String = broadcast
           Return b.SubString(1)
         End If
       Next
     End If
   Loop
   Return ""
End Sub
but it always return empty string.
I can receive udp packets.
I can send udp packets but using hardcoded address 192.168.0.255
what could be the cause?

Many thanks.

here is the content of manifest
Manifest content:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="28" android:targetSdkVersion="33"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
AddPermission("android.permission.INTERNET")
SetActivityAttribute(ViewCam, android:screenOrientation, "landscape")
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:allowBackup, "false")
CreateResourceFromFile(Macro, Themes.DarkTheme)
SetApplicationAttribute(android:usesCleartextTraffic, "true")
'End of default text.
 
Top