I'm trying to my application to retrieve the IP address when it's connected to the Wifi network but I'm not too sure how to get that done.
I've looked at RadioInfo and there's a function getIPAddress(int apnId). Is this the right one?
I've also looked at WLANInfo but that one doesn't seem to have any IP related functions开发者_运维知识库.
Anyone can help me with this?
klyubin wrote:
[...] the best solution (as it relies on documented behavior) is to open a udp socket (or TCP server socket) over WiFi and query its IP address. Another hack is to get the APN ID for the "MagicRudyAPN.rim" using getAccessPointNumber, and then query its IP address using getIPAddress. MagicRudyAPN.rim seems to be a virtual/fake APN for accessing/addressing the IP tunnel to the WiFi network.
int apnId = RadioInfo.getAccessPointNumber("MagicRudyAPN.rim");
byte[] ipByte = RadioInfo.getIPAddress(apnId);
String ip = "";
for (int i = 0; i < ipByte.length; i++) {
int temp = (ipByte[i] & 0xff);
if (i < 3)
ip = ip.concat("" + temp + ".");
else {
ip = ip.concat("" + temp);
}
}
精彩评论