2
我想找到任何黑莓設備的IP/MAC地址,所以我應該如何得到它programatically.please幫助我。如何獲取任何黑莓設備的IP/MAC地址?
我想找到任何黑莓設備的IP/MAC地址,所以我應該如何得到它programatically.please幫助我。如何獲取任何黑莓設備的IP/MAC地址?
public static String getIPAddress() {
int apnId = 0;
try {
apnId = RadioInfo.getAccessPointNumber("MagicRudyAPN.rim");
} catch (RadioException e) {
Log.e(e);
e.printStackTrace();
}
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);
}
}
Log.s(TAG + "Returning IP=" + ip);
return ip;
}
我發現這個代碼,我工作得很好......
protected String getIpAddress() {
String ip = new String("");
try {
int cni = RadioInfo.getCurrentNetworkIndex();
int apnId = cni + 1; // cni is zero based
byte[] ipaddr = RadioInfo.getIPAddress(apnId);
for (int i = 0; i < ipaddr.length; i++) {
int temp = (ipaddr[i] & 0xff);
if (i < 3) {
ip = ip.concat("" + temp + ".");
} else {
ip = ip.concat("" + temp);
}
}
} catch (Exception e) {
ip = null;
}
return ip;
}
這是什麼MagicRudyAPN.rim。因爲上面的代碼每次返回的IP地址爲0.0.0.0 – 1001 2012-04-03 08:07:22
我可以知道嗎我應該如何檢索設備的MAC地址? – 1001 2012-04-26 15:09:10