Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Bluetooth discoverable mode on Android

I found in the Android documentation how to turn Bluetooth discoverability mode on:

Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);

This will make the device discoverable for 300 seconds (documentation).

My question is: how to turn discoverability OFF before this timeout occurs? I'd like to replicate the corresponding setting in Settings|Wireless and networks|Bluetooth settings applet, that allows discoverability to be turned on and off with a click.

Any help?

like image 255
Venator85 Avatar asked May 30 '10 11:05

Venator85


2 Answers

Just send a new discoverable request with duration 1 (or 0 might even work):

Intent discoverableIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 1);
startActivity(discoverableIntent);
like image 169
Brad Hein Avatar answered Oct 04 '22 04:10

Brad Hein


cancelDiscovery() is not for this. This method can be used to stop the scanning of your device for other bluetooth devices. It is different from this to make device not visible.

like image 43
cotalfa Avatar answered Oct 04 '22 04:10

cotalfa