public final class BluetoothHealth
extends Object implements BluetoothProfile
| java.lang.Object | |
| android.bluetooth.BluetoothHealth | |
蓝牙健康档案的公共API。
BluetoothHealth是通过IPC控制蓝牙服务的代理对象。
如何连接到以源角色行事的健康设备。
getProfileProxy(Context, BluetoothProfile.ServiceListener, int) to get the BluetoothHealth proxy object. BluetoothHealth callback and call registerSinkAppConfiguration(String, int, BluetoothHealthCallback) to register an application configuration connectChannelToSource(BluetoothDevice, BluetoothHealthAppConfiguration). Some devices will connect the channel automatically. The BluetoothHealth callback will inform the application of channel state change. disconnectChannel(BluetoothDevice, BluetoothHealthAppConfiguration, int) and unregister the application configuration calling unregisterAppConfiguration(BluetoothHealthAppConfiguration) 常量(Constants) |
|
|---|---|
int |
APP_CONFIG_REGISTRATION_FAILURE 健康应用配置注册失败 |
int |
APP_CONFIG_REGISTRATION_SUCCESS 健康应用配置注册成功 |
int |
APP_CONFIG_UNREGISTRATION_FAILURE 健康应用程序配置取消注册失败 |
int |
APP_CONFIG_UNREGISTRATION_SUCCESS 健康应用程序配置取消注册成功 |
int |
CHANNEL_TYPE_RELIABLE 健康档案 - 使用的频道类型 - 可靠 |
int |
CHANNEL_TYPE_STREAMING 健康档案 - 使用的频道类型 - 串流 |
int |
SINK_ROLE Health Profile Sink角色设备与健康设备通话。 |
int |
SOURCE_ROLE 健康档案源角色 - 健康设备。 |
int |
STATE_CHANNEL_CONNECTED 健康通道连接状态 - 已连接 |
int |
STATE_CHANNEL_CONNECTING 健康通道连接状态 - 连接 |
int |
STATE_CHANNEL_DISCONNECTED 健康通道连接状态 - 断开连接 |
int |
STATE_CHANNEL_DISCONNECTING 健康通道连接状态 - 断开连接 |
Inherited constants |
|---|
android.bluetooth.BluetoothProfile
|
公共方法(Public methods) |
|
|---|---|
boolean |
connectChannelToSource(BluetoothDevice device, BluetoothHealthAppConfiguration config) 连接到具有 |
boolean |
disconnectChannel(BluetoothDevice device, BluetoothHealthAppConfiguration config, int channelId) 断开连接的健康渠道。 |
List<BluetoothDevice> |
getConnectedDevices() 获取健康档案的连接设备。 |
int |
getConnectionState(BluetoothDevice device) 获取配置文件的当前连接状态。 |
List<BluetoothDevice> |
getDevicesMatchingConnectionStates(int[] states) 获取匹配任何给定连接状态的设备列表。 |
ParcelFileDescriptor |
getMainChannelFd(BluetoothDevice device, BluetoothHealthAppConfiguration config) 获取与远程设备和应用程序配置关联的主要通道的文件描述符。 |
boolean |
registerSinkAppConfiguration(String name, int dataType, BluetoothHealthCallback callback) 注册充当Health SINK的应用程序配置。 |
boolean |
unregisterAppConfiguration(BluetoothHealthAppConfiguration config) 取消注册已使用 需要 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
android.bluetooth.BluetoothProfile
|
|
int APP_CONFIG_REGISTRATION_FAILURE
健康应用配置注册失败
常数值:1(0x00000001)
int APP_CONFIG_REGISTRATION_SUCCESS
健康应用配置注册成功
常量值:0(0x00000000)
int APP_CONFIG_UNREGISTRATION_FAILURE
健康应用程序配置取消注册失败
常量值:3(0x00000003)
int APP_CONFIG_UNREGISTRATION_SUCCESS
健康应用程序配置取消注册成功
常量值:2(0x00000002)
int CHANNEL_TYPE_RELIABLE
健康档案 - 使用的频道类型 - 可靠
常量值:10(0x0000000a)
int CHANNEL_TYPE_STREAMING
健康档案 - 使用的频道类型 - 串流
常量值:11(0x0000000b)
int STATE_CHANNEL_CONNECTED
健康通道连接状态 - 已连接
常量值:2(0x00000002)
int STATE_CHANNEL_CONNECTING
健康通道连接状态 - 连接
常数值:1(0x00000001)
int STATE_CHANNEL_DISCONNECTED
健康通道连接状态 - 断开连接
常量值:0(0x00000000)
int STATE_CHANNEL_DISCONNECTING
健康通道连接状态 - 断开连接
常量值:3(0x00000003)
boolean connectChannelToSource (BluetoothDevice device, BluetoothHealthAppConfiguration config)
连接到具有SOURCE_ROLE的健康设备。 这是一个异步调用。 如果此函数返回true,则将调用与应用程序配置关联的回调。
需要 BLUETOOTH权限。
| 参数(Parameters) | |
|---|---|
device |
BluetoothDevice: The remote Bluetooth device. |
config |
BluetoothHealthAppConfiguration: The application configuration which has been registered using registerSinkAppConfiguration(String, int, BluetoothHealthCallback) |
| 返回(Returns) | |
|---|---|
boolean |
If true, the callback associated with the application config will be called. |
boolean disconnectChannel (BluetoothDevice device, BluetoothHealthAppConfiguration config, int channelId)
断开连接的健康渠道。 这是一个异步调用。 如果此函数返回true,则将调用与应用程序配置关联的回调。
需要 BLUETOOTH权限。
| 参数(Parameters) | |
|---|---|
device |
BluetoothDevice: The remote Bluetooth device. |
config |
BluetoothHealthAppConfiguration: The application configuration which has been registered using registerSinkAppConfiguration(String, int, BluetoothHealthCallback) |
channelId |
int: The channel id associated with the channel |
| 返回(Returns) | |
|---|---|
boolean |
If true, the callback associated with the application config will be called. |
List<BluetoothDevice> getConnectedDevices ()
获取健康档案的连接设备。
返回处于状态 STATE_CONNECTED的设备 STATE_CONNECTED
需要BLUETOOTH权限。 这不是特定于任何应用程序配置,而是代表本配置文件的本地蓝牙适配器的连接状态。 这可以被像状态栏这样的应用程序使用,它只是想知道本地适配器的状态。
| 返回(Returns) | |
|---|---|
List<BluetoothDevice> |
List of devices. The list will be empty on error. |
int getConnectionState (BluetoothDevice device)
获取配置文件的当前连接状态。
需要BLUETOOTH权限。 这不是特定于任何应用程序配置,而是表示本地蓝牙适配器与远程设备的连接状态。 这可以被像状态栏这样的应用程序使用,它只是想知道本地适配器的状态。
| 参数(Parameters) | |
|---|---|
device |
BluetoothDevice: Remote bluetooth device. |
| 返回(Returns) | |
|---|---|
int |
State of the profile connection. One of STATE_CONNECTED, STATE_CONNECTING, STATE_DISCONNECTED, STATE_DISCONNECTING |
List<BluetoothDevice> getDevicesMatchingConnectionStates (int[] states)
获取匹配任何给定连接状态的设备列表。
如果没有任何设备匹配任何给定的状态,则会返回空列表。
需要BLUETOOTH权限。 这不是特定于任何应用程序配置,而是代表本配置文件的本地蓝牙适配器的连接状态。 这可以被像状态栏这样的应用程序使用,它只是想知道本地适配器的状态。
| 参数(Parameters) | |
|---|---|
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. |
ParcelFileDescriptor getMainChannelFd (BluetoothDevice device, BluetoothHealthAppConfiguration config)
获取与远程设备和应用程序配置关联的主要通道的文件描述符。
需要 BLUETOOTH权限。
调用者完成后关闭ParcelFileDescriptor的责任。
| 参数(Parameters) | |
|---|---|
device |
BluetoothDevice: The remote Bluetooth health device |
config |
BluetoothHealthAppConfiguration: The application configuration |
| 返回(Returns) | |
|---|---|
ParcelFileDescriptor |
null on failure, ParcelFileDescriptor on success. |
boolean registerSinkAppConfiguration (String name, int dataType, BluetoothHealthCallback callback)
注册充当Health SINK的应用程序配置。 这是将用于与充当SOURCE_ROLE健康设备进行通信的配置。 这是一个异步调用,因此如果函数返回true,则使用回调来通知成功或失败。
需要 BLUETOOTH权限。
| 参数(Parameters) | |
|---|---|
name |
String: The friendly name associated with the application or configuration. |
dataType |
int: The dataType of the Source role of Health Profile to which the sink wants to connect to. |
callback |
BluetoothHealthCallback: A callback to indicate success or failure of the registration and all operations done on this application configuration. |
| 返回(Returns) | |
|---|---|
boolean |
If true, callback will be called. |
boolean unregisterAppConfiguration (BluetoothHealthAppConfiguration config)
取消注册已使用 registerSinkAppConfiguration(String, int, BluetoothHealthCallback)注册的应用程序配置
需要 BLUETOOTH权限。
| 参数(Parameters) | |
|---|---|
config |
BluetoothHealthAppConfiguration: The health app configuration |
| 返回(Returns) | |
|---|---|
boolean |
Success or failure. |