Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable Android bluetooth from documentation

I am trying to get my Activity to enable Bluetooth with the Android 2.0.1 SDK, I am using some code straight from the documentation here: http://developer.android.com/guide/topics/wireless/bluetooth.html

Which is:

if (!mBluetoothAdapter.isEnabled()) {
    Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
    startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}

I get an error at the REQUEST_ENABLE_BT part where Eclipse says it cannot be resolved. What am I doing wrong?

like image 552
trobrock Avatar asked Dec 29 '09 16:12

trobrock


People also ask

How Bluetooth can be made available through program?

In order to enable the Bluetooth of your device, call the intent with the following Bluetooth constant ACTION_REQUEST_ENABLE. Its syntax is. Intent turnOn = new Intent(BluetoothAdapter. ACTION_REQUEST_ENABLE); startActivityForResult(turnOn, 0);

Why is Bluetooth not finding devices?

It's usually because the device's own Bluetooth is switched off, or isn't in pairing mode. Check the user manual to find out how to make it discoverable by turning on pairing mode. With some headphones, it's a case of holding the power button down for longer, but with other devices there's a dedicated Bluetooth button.


1 Answers

The REQUEST_ENABLE_BT part is a request code that you should handle in your onActivityResult method. In that method you'll be notified whether or not enabling Bluetooth was successful.

In that code snippet they didn't show the definition of it, but it's just a constant integer so you can set it to any value you like.

See the documentation for startActivityForResult for more info about getting results back from activity launches.

like image 164
Christopher Orr Avatar answered Oct 07 '22 19:10

Christopher Orr