Wifi の切り替えはWifiManager クラスで設定する。
Wifiの有効設定は setWifiEnabled で設定、ステータスは getSystemService(WIFI_SERVICE) で取得する。 [java] private void changeWifiService(boolean isWifi) { WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); if (wifiManager != null) { wifiManager.setWifiEnabled(isWifi); wifiStatus(); } }
public void wifiStatus() {
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
int wifiState = wifiManager.getWifiState();
switch (wifiState) {
case WifiManager.WIFI_STATE_DISABLING:
Log.d("WifiState", "WIFI_STATE_DISABLING");
break;
case WifiManager.WIFI_STATE_DISABLED:
Log.v("WifiState", "WIFI_STATE_DISABLED");
break;
case WifiManager.WIFI_STATE_ENABLING:
Log.d("WifiState", "WIFI_STATE_ENABLING");
break;
case WifiManager.WIFI_STATE_ENABLED:
Log.d("WifiState", "WIFI_STATE_ENABLED");
break;
case WifiManager.WIFI_STATE_UNKNOWN:
Log.d("WifiState", "WIFI_STATE_UNKNOWN");
break;
}
}
[/java]