I have an Android app that needs the real IP of the device, not the virtual network IP. I don't want the the public IP unless the Chromebook is on a public IP, I just need the private one of the LAN, but right now I'm getting a virtual IP of what I'm guessing is a virtual network for Android apps.
Using both WifiManager
and NetworkInterface.getNetworkInterfaces()
all I get is the virtual IP. Calling an external server won't work because that would get me the public IP.
I know this has been asked in the past but I just want to check if anyone has found a way yet?
This is answered in more detail on ChromeOS.dev.
To get the IPv4 address assigned to the highest priority network that the Chrome OS device is connected to, examine the android system property arc.net.ipv4.host_address and, if needed, arc.net.ipv4.host_gateway. One way to do this is:
fun getChromeOsIpAddress() : String {
val process = ProcessBuilder().command("/system/bin/getprop", "arc.net.ipv4.host_address").start()
val ipAddress = readInput(process.inputStream)
return ipAddress
}
fun getChromeOsIpGateway() : String {
val process = ProcessBuilder().command("/system/bin/getprop", "arc.net.ipv4.host_gateway").start()
val gatewayAddress = readInput(process.inputStream)
return gatewayAddress
}
This post is licensed under Apache 2.0.