启用从文档Android的蓝牙蓝牙、文档、Android

2023-09-04 08:37:31 作者:回眸丶忆红颜

我试图让我的活动,以启用蓝牙的Andr​​oid 2.0.1 SDK,我使用从这里的文档一些code直: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 部分是一个请求code,你应该处理在 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.

在这code段,他们并没有表现出它的定义,但它只是一个恒定的整数,所以你可以将其设置为任何你喜欢的值。

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.

见documentation对于startActivityForResult 了解有关从活动的推出获得返回结果的详细信息。

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