Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I usually use this

C#
private void ensureDiscoverable() {
        if(D) Log.d(TAG, "ensure discoverable");
        if (mBluetoothAdapter.getScanMode() !=
                BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
            Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
            discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
            startActivity(discoverableIntent);
        }
    }



But that prompts a user confirmation. Is there a way to bypass this programmatically?

I eventually found this
http://www.devdaily.com/java/jwarehouse/android/core/java/android/bluetooth/BluetoothAdapter.java.shtml[^]

but unfortunately the setDiscoverableTimeout doesnt work.
Posted
Updated 10-Jan-12 5:01am
v2
Comments
TorstenH. 10-Jan-12 13:47pm    
Why does this need a user acknowledge? That is from a tutorial her:
http://developer.android.com/resources/samples/BluetoothChat/src/com/example/android/BluetoothChat/BluetoothChat.html

You should change/overwrite it when you want to change that method.
Maxdd 7 10-Jan-12 14:41pm    
I know that sample very well - every time you do that discoverableIntent, that prompts the user for confirmation - that is what I want to avoid.

1 solution

AFAIK it is a design feature of the Bluetooth adapter that the user of the device must start or stop the discoverabilty. That is why the action is called ACTION_REQUEST_DISCOVERABLE and not ACTION_DISCOVERABLE.
 
Share this answer
 
Comments
Maxdd 7 10-Jan-12 16:09pm    
Yes, but the taking into account there is a "action request enable" to enable bluetooth, there is also a way to enable programatically BT without user interaction (using .enable), I was wondering if it possible to do the same with discoverable timeout.
gumuruh 7-Jul-14 2:25am    
have you done it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900