需要以编程方式打开蓝牙,发现在Android设备 [英] Need to programmatically open bluetooth and discover devices in Android

查看:171
本文介绍了需要以编程方式打开蓝牙,发现在Android设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要通过我的code打开蓝牙,而不要求用户启用它,然后发现在范围内的所有设备,并返回这些设备,然后关闭蓝牙连接。

I need to open up bluetooth through my code without asking the user to enable it and then discover all the devices in range and return those devices and then close bluetooth connection.

怎么办呢?

推荐答案

我想,这里正是你所需要的。

I suppose here is exactly what you need.

http://developer.android.com/guide/topics/wireless/bluetooth.html#FindingDevices

http://developer.android.com/guide/topics/wireless/bluetooth.html#DiscoveringDevices

关于启用蓝牙无需询问用户,这里是什么医生说:

About enabling the Bluetooth without asking the user, here is what the doc says:

蓝牙不应该没有直接的用户同意的情况下启用。如果你   要开启蓝牙以   创建无线连接,   应使用ACTION_REQUEST_ENABLE   意图,这将提高一个对话框,   要求用户权限打开   蓝牙。使能()方法是   只为应用程序提供的   包括用于改变用户界面   系统设置,例如电源   经理人的应用程序。

Bluetooth should never be enabled without direct user consent. If you want to turn on Bluetooth in order to create a wireless connection, you should use the ACTION_REQUEST_ENABLE Intent, which will raise a dialog that requests user permission to turn on Bluetooth. The enable() method is provided only for applications that include a user interface for changing system settings, such as a "power manager" app.

但如果你真的要启用蓝牙设备,而不询问用户。后补充一点:

But if you really want to Enable device bluetooth without asking the user. after add this:

 <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

允许在你的应用程序的清单使用本code

permission to your Manifest use this code in your App

BluetoothAdapter.enable()

这篇关于需要以编程方式打开蓝牙,发现在Android设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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