2012-04-03 12 views

Antwort

2
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; 

}

siehe wifi-ip-address

+0

was diese MagicRudyAPN.rim ist. weil über Code, der IP Adresse als 0.0.0.0 jedes Mal zurückbringt – 1001

+0

Kann ich kno w wie soll ich die MAC-Adresse des Geräts abrufen? – 1001

0

ich diesen Code gefunden, funktioniert gut für mich ...

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

Siehe: BlackBerry forum

Verwandte Themen