AndroidでWiFiを簡単に有効/無効にする処理方法

1.必要なアクセス権限を設定
android.permission.ACCESS_WIFI_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.WAKE_LOCK

2.WifiManagerを取得
wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);

3.wifiを有効/無効にする
if (wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(false);
} else {
wifiManager.setWifiEnabled(true);
}

Android

Posted by arkgame