I am developing an Android application which will access the Bluetooth to enable and disable it without any user interaction. Can somebody help me on how to do it?
Discover local Bluetooth devices If you want your app to initiate device discovery or manipulate Bluetooth settings, you must declare the BLUETOOTH_ADMIN permission. Most apps need this permission solely for the ability to discover local Bluetooth devices.
Call isEnabled() to check whether Bluetooth is currently enabled. If this method returns false, then Bluetooth is disabled. To request that Bluetooth be enabled, call startActivityForResult() , passing in an ACTION_REQUEST_ENABLE intent action.
1- If you want to search nearby Bluetooth devices, you must add BLUETOOTH_SCAN permission. 2- If you want your device to be discovered by other devices, you must add BLUETOOTH_ADVERTISE permission. 3- If you want your device to be communicable with other devices, you must add BLUETOOTH_CONNECT permission.
You can do this by using BluetoothAdapter:
BluetoothAdapter.getDefaultAdapter().disable();
BluetoothAdapter.getDefaultAdapter().enable();
And add ths permission to manifest:
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With