I am able to turn on/off Bluetooth without any prompt using the following code. It requires BLUETOOTH
and BLUETOOTH_ADMIN
permissions.
boolean isEnabled = bluetoothAdapter.isEnabled();
if (enable && !isEnabled) {
return bluetoothAdapter.enable();
} else if (!enable && isEnabled) {
return bluetoothAdapter.disable();
}
But didn't find any way to set Bluetooth discoverable without user prompt. It's wired to prompt every time to user. There is no "don't ask me again" feature I afraid. Is there any good way to make Bluetooth device discoverable? I don't care about the duration. Also my device is not rooted.
More Info
I found source code of BluetoothAdapter.java and it has a public method named setDiscoverableDuration
. But why I can't access it? Why some public methods are hidden in Api documentations? How did they even do that? all methods are public.