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" />
More Posts related to Android,
- Change Android Toast background color
- Maven : java.lang.ClassNotFoundException: Xmx512m
- This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView) Lint Error
- Android Alert Dialog with Checkboxes example
- Android Error Generating Final Archive - Debug Certificate Expired
- How to add Newline to text in Android TextView
- Read Text file from SD Card : Android Programming
- [FIX] AndroidRuntime: FATAL EXCEPTION: main - java.lang.RuntimeException NullPointerException
- ActivityManager Warning: Activity not started, its current task has been brought to the front
- INSTALL_FAILED_INSUFFICIENT_STORAGE Android Error
- Android Developers Bluetooth Tutorial
- java.lang.ClassNotFoundException android.support.v7.widget.Toolbar [Fix]
- Android: Save Data in local Db using Android Room
- Channel 50 SMSes received every few minutes Android Phones
- 21 Useful Android Emulator Short-cut Keyboard Keys
- Changing Android Intent Tittle using java code
- Android : No Launcher activity found! Error
- How to change TextView or EditText Text Color on Focus and on Press
- How to display Toast on Button Click : Android
- Android : Execute some code after back button is pressed
- Stop android adb service from command prompt or terminal
- [Soluiton] You already have the latest version of Android Studio installed
- Create Custom Android AlertDialog
- Android R Cannot Be Resolved To A Variable
- How to make Android EditText not editable
More Posts:
- How to remove Siri from Menu Bar [macOS Big Sur] - MacOS
- How to fix Microsoft Windows 10 update error 80070020 - Microsoft
- Bootstrap Nav Menu Dropdown on hover - Bootstrap
- Android Parsing Data for android-L failed Unsupported major.minor version 51.0 Error - Android
- How to open a new tab in Notepad++ - NotepadPlusPlus
- Notepad++ Editor alternatives for Mac OS X - NotepadPlusPlus
- Create SharePoint Site Collection with new Content database in existing web application - SharePoint
- Change Height of Android ActionBar - Android