How to Enable/Disable Bluetooth Programmatically in Android

How to enable/disable bluetooth programmatically in android

Android BluetoothAdapter docs say it has been available since API Level 5. API Level 5 is Android 2.0.

You can try using a backport of the Bluetooth API (have not tried it personally): http://code.google.com/p/backport-android-bluetooth/

Turn device bluetooth on or off

Firstly you need to add these permissions

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

and to Enable/Disable Bluetooth programmatically use BluetoothAdapter
for example:

btnBluetooth.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter.isEnabled()){
adapter.disable();
} else {
adapter.enable();
}
} });

For more information check Bluetooth Docs

Enable Disable Bluetooth in Android

You might want to read the Android documentation to find the answer yourself:
http://developer.android.com/guide/topics/wireless/bluetooth.html



Related Topics



Leave a reply



Submit