title: Android disable/enable Wifi and Bluetooth permanently
body: <p>I have an application that should manage the wifi and bluetooth state of a devices. For that it receives an message with the state and wheter or not this state should be forced. Then it applies the state and saves both values.</p>
  
  <p>For example: i send an message to disable wifi and force it. Then i turn wifi off and save the state and that this is forced. Also i have a BroadcastReceiver that listens to Wifi state changes and if received, it first checks if wifi was enabled and if that is okay. if not, it instantly disables wifi again. That works like a charm:
  public class WifiStateReceiver extends BroadcastReceiver {</p>
  
  <pre><code>public void onReceive(final Context context, final Intent intent) {
      // get new wifi state
      final int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_ENABLING);
      final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
  
      // if enabling, check if thats okay
      if (wifiState == WifiManager.WIFI_STATE_ENABLING &amp;&amp; WIFI_FORCE_DISABLE) {
          wifiManager.setWifiEnabled(false);
      } else
  
      // if disabling, check if thats okay
      if (wifiState == WifiManager.WIFI_STATE_DISABLING &amp;&amp; WIFI_FORCE_ENABLE) {
          wifiManager.setWifiEnabled(true);
      }
  }
  </code></pre>
  
  <p>But if i try the exact same thing with bluetooth, it doesnt switch it back...</p>
  
  <pre><code>public void onReceive(final Context context, final Intent intent) {
      // get new wifi state
      final int bluetoothState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_ON);
      final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  
      // if enabling, check if thats okay
      if (bluetoothState == BluetoothAdapter.STATE_TURNING_ON &amp;&amp; BT_FORCE_DISABLE) {
          mBluetoothAdapter.disable();
      } else
  
      // if disabling, check if thats okay
      if (bluetoothState == BluetoothAdapter.STATE_TURNING_OFF &amp;&amp; BT_FORCE_ENABLE) {
          mBluetoothAdapter.enable();
      }
  }
  </code></pre>
  
  <p>Any ideas how i can disable bluetooth permanently?</p>