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?
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);
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.
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.
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