「android開発」android端末の無線LAN WiFIのIPアドレスを取得するサンプルコード
Javaコード:
@SuppressWarnings(“deprecation")
public static String IPAnalysis(Context context) {
//wifiを取得
WifiManager wifiManager = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
//wifi無効/有効の判断
if (!wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(true);
}
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int mAddress = wifiInfo.getIpAddress();
Log.d(“IPAddress—> “, Formatter.formatIpAddress(mAddress));
return Formatter.formatIpAddress(mAddress);
}