启用从文档Android的蓝牙 [英] Enable Android bluetooth from documentation

查看:137
本文介绍了启用从文档Android的蓝牙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的活动,以启用蓝牙的Andr​​oid 2.0.1 SDK,我使用从这里的文档一些code直:<一href="http://developer.android.com/guide/topics/wireless/bluetooth.html">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.

见<一href="http://developer.android.com/reference/android/app/Activity.html#startActivityForResult%28android.content.Intent,%20int%29">documentation对于startActivityForResult 了解有关从活动的推出获得返回结果的详细信息。

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

这篇关于启用从文档Android的蓝牙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆