/**
* wifi 상태인지 확인
* @param context
* @return
*/
public static boolean isWifiEnabled(Context context) {
WifiManager wifiMgr = (WifiManager)context
.getSystemService(Context.WIFI_SERVICE);
if(wifiMgr.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
return true;
} else {
return false;
}
}
/**
* wifi 주소 int 값 리턴
* @param context
* @return
*/
public static int getWifiIpAsInt(Context context) {
WifiManager wifiMgr = (WifiManager)context
.getSystemService(Context.WIFI_SERVICE);
if(wifiMgr.isWifiEnabled()) {
return wifiMgr.getConnectionInfo().getIpAddress();
} else {
return 0;
}
}
/**
* wifi 주소 string 리턴
* @param context
* @return
*/
public static String getWifiIpAsString(Context context) {
int addr = getWifiIpAsInt(context);
if(addr != 0) {
StringBuffer buf = new StringBuffer();
buf.append(addr & 0xff).append('.').
append((addr >>>= 8) & 0xff).append('.').
append((addr >>>= 8) & 0xff).append('.').
append((addr >>>= 8) & 0xff);
return buf.toString();
} else {
return null;
}
}