How to enable or disable Bluetooth in android programmatically

In this post, we will see how to enable or disable Bluetooth in android programmatically.
It is very simple to enable or disable bluetooth from android code.
For enabling Bluetooth:
For disabling Bluetooth:
So you can enable or disable Bluetooth using BluetoothAdapter class.
You need to add extra permissions in AndroidManifest.xml to enable or disable Bluetooth.

Source code:

Download

click to begin
20KB .zip

Step 1 :

Create an android application project named “EnableDisableBluetoothApp”.

Step 2:

Add following permissions in AndoridManifest.xml.

Step 3 :

Change res ->layout -> activity_main.xml as below:

Step 4:

Change src/main/packageName/MainActivity.java as below:

Step 5:

Run the app
When you run the app, you will get below screen:

When you click on toggle button, you will get below screen:

Was this post helpful?

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *