Most visited

Recently visited

Added in API level 18

BluetoothManager

public final class BluetoothManager
extends Object

java.lang.Object
    android.bluetooth.BluetoothManager


高级经理用于获取 BluetoothAdapter的实例并进行整体蓝牙管理。

使用 getSystemService(java.lang.String)BLUETOOTH_SERVICE创建一个 BluetoothManager ,然后调用 getAdapter()以获得 BluetoothAdapter

或者,您可以拨打静态帮助程序 getDefaultAdapter()

Developer Guides

有关使用BLUETOOTH的更多信息,请阅读 Bluetooth开发人员指南。

也可以看看:

摘要(Summary)

公共方法(Public methods)

BluetoothAdapter getAdapter()

获取此设备的默认BLUETOOTH适配器。

List<BluetoothDevice> getConnectedDevices(int profile)

获取指定配置文件的连接设备。

int getConnectionState(BluetoothDevice device, int profile)

获取配置文件的当前连接状态到远程设备。

List<BluetoothDevice> getDevicesMatchingConnectionStates(int profile, int[] states)

获取匹配任何给定连接状态的设备列表。

BluetoothGattServer openGattServer(Context context, BluetoothGattServerCallback callback)

打开GATT服务器回调函数用于将结果传递给呼叫者,例如连接状态以及任何其他GATT服务器操作的结果。

继承方法(Inherited methods)

From class java.lang.Object

公共方法(Public methods)

getAdapter

Added in API level 18
BluetoothAdapter getAdapter ()

获取此设备的默认BLUETOOTH适配器。

返回(Returns)
BluetoothAdapter the default BLUETOOTH Adapter

getConnectedDevices

Added in API level 18
List<BluetoothDevice> getConnectedDevices (int profile)

获取指定配置文件的连接设备。

返回处于状态 STATE_CONNECTED的一组设备

这不是特定于任何应用程序配置,而是表示此配置文件的蓝牙连接状态。 这可以被像状态栏这样的应用程序使用,它只是想知道蓝牙的状态。

需要 BLUETOOTH权限。

参数(Parameters)
profile int: GATT or GATT_SERVER
返回(Returns)
List<BluetoothDevice> List of devices. The list will be empty on error.

getConnectionState

Added in API level 18
int getConnectionState (BluetoothDevice device, 
                int profile)

获取配置文件的当前连接状态到远程设备。

这不是特定于任何应用程序配置,而是表示某个配置文件的本地蓝牙适配器的连接状态。 这可以被像状态栏这样的应用程序使用,它只是想知道蓝牙的状态。

需要 BLUETOOTH权限。

参数(Parameters)
device BluetoothDevice: Remote bluetooth device.
profile int: GATT or GATT_SERVER
返回(Returns)
int State of the profile connection. One of STATE_CONNECTED, STATE_CONNECTING, STATE_DISCONNECTED, STATE_DISCONNECTING

getDevicesMatchingConnectionStates

Added in API level 18
List<BluetoothDevice> getDevicesMatchingConnectionStates (int profile, 
                int[] states)

获取匹配任何给定连接状态的设备列表。

如果没有任何设备匹配任何给定的状态,则会返回空列表。

这不是特定于任何应用程序配置,而是代表本配置文件的本地蓝牙适配器的连接状态。 这可以被像状态栏这样的应用程序使用,它只是想知道本地适配器的状态。

需要 BLUETOOTH权限。

参数(Parameters)
profile int: GATT or GATT_SERVER
states int: Array of states. States can be one of STATE_CONNECTED, STATE_CONNECTING, STATE_DISCONNECTED, STATE_DISCONNECTING,
返回(Returns)
List<BluetoothDevice> List of devices. The list will be empty on error.

openGattServer

Added in API level 18
BluetoothGattServer openGattServer (Context context, 
                BluetoothGattServerCallback callback)

打开GATT服务器回调函数用于将结果传递给呼叫者,例如连接状态以及任何其他GATT服务器操作的结果。 该方法返回一个BluetoothGattServer实例。 您可以使用BluetoothGattServer来执行GATT服务器操作。

参数(Parameters)
context Context: App context
callback BluetoothGattServerCallback: GATT server callback handler that will receive asynchronous callbacks.
返回(Returns)
BluetoothGattServer BluetoothGattServer instance

Hooray!