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



Recent Posts:




Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.