Android: programmatically turn Bluetooth on or off using Java code


If you are looking to know if the Bluetooth device is turned on or off you follow the below tutorial,

✔️ Check Bluetooth is turned on or off on Android device programmatically [Java Code]

If you are looking to programmatically turn off or on the Bluetooth then you can follow this tutorial. You need to make use of the BluetoothAdapter class,

Example to turn on the Bluetooth programmatically:

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
bluetoothAdapter.enable();

Example to turn off the Bluetooth programmatically:

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
bluetoothAdapter.disable();

Note: Make sure you add the two below permissions in the AndoridManifest.xml file or else you will get Runtime errors,

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
Toggle Bluetooth Android Code Example





      Topics: Pages | 2015 | Tutorials | Questions | Python