How to Enable Bluetooth Android programmatically

Prawin
2 min readJun 15, 2024

Hello everyone! πŸ‘‹

In this article, I will explain how to enable Bluetooth on an Android device using Java. This method is compatible with both newer and older Android devices.

Bluetooth Permission πŸ“±πŸ”’

Target Android 12 or Higher

Declare the Bluetooth Connect permission in the manifest file and request at runtime.

<manifest>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"
</manifest>
requestPermissions(new String[]{android.Manifest.permission.BLUETOOTH_CONNECT},100);

Target Android 11 or Lower

Declare the Bluetooth permission in the manifest file.

<uses-permission android:name="android.permission.BLUETOOTH"/>

Request To Enable Bluetooth πŸ“Ά

ActivityResultLauncher

First, declare and initialize the ActivityResultLauncher to handle the result of enabling Bluetooth.

Note: Register the ActivityResultLauncher inside the onCreate() lifecycle method.

// Declare the ActivityResultLauncher
ActivityResultLauncher<Intent>…

--

--