从文档中启用 Android 蓝牙 [英] Enable Android bluetooth from documentation
问题描述
我正在尝试让我的 Activity 使用 Android 2.0.1 SDK 启用蓝牙,我直接使用此处文档中的一些代码:http://developer.android.com/guide/topics/wireless/bluetooth.html
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
是:
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
我在 REQUEST_ENABLE_BT 部分收到一个错误,Eclipse 说它无法解决.我做错了什么?
I get an error at the REQUEST_ENABLE_BT part where Eclipse says it cannot be resolved. What am I doing wrong?
推荐答案
REQUEST_ENABLE_BT
部分是您应该在 onActivityResult
方法中处理的请求代码.在该方法中,您会收到是否启用蓝牙成功的通知.
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.
请参阅文档为 startActivityForResult 了解有关从活动启动中获取结果的更多信息.
See the documentation for startActivityForResult for more info about getting results back from activity launches.
这篇关于从文档中启用 Android 蓝牙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!