Most visited

Recently visited

Added in API level 14

BluetoothHealth

public final class BluetoothHealth
extends Object implements BluetoothProfile

java.lang.Object
   ↳ android.bluetooth.BluetoothHealth


蓝牙健康档案的公共API。

BluetoothHealth是通过IPC控制蓝牙服务的代理对象。

如何连接到以源角色行事的健康设备。

  • Use getProfileProxy(Context, BluetoothProfile.ServiceListener, int) to get the BluetoothHealth proxy object.
  • Create an BluetoothHealth callback and call registerSinkAppConfiguration(String, int, BluetoothHealthCallback) to register an application configuration
  • Pair with the remote device. This currently needs to be done manually from Bluetooth Settings
  • Connect to a health device using connectChannelToSource(BluetoothDevice, BluetoothHealthAppConfiguration). Some devices will connect the channel automatically. The BluetoothHealth callback will inform the application of channel state change.
  • Use the file descriptor provided with a connected channel to read and write data to the health channel.
  • The received data needs to be interpreted using a health manager which implements the IEEE 11073-xxxxx specifications.
  • When done, close the health channel by calling disconnectChannel(BluetoothDevice, BluetoothHealthAppConfiguration, int) and unregister the application configuration calling unregisterAppConfiguration(BluetoothHealthAppConfiguration)

    Summary

    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

    From interface android.bluetooth.BluetoothProfile

    Public methods

    boolean connectChannelToSource(BluetoothDevice device, BluetoothHealthAppConfiguration config)

    连接到具有 SOURCE_ROLE的健康设备。

    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)

    取消注册已使用 registerSinkAppConfiguration(String, int, BluetoothHealthCallback)注册的应用程序配置

    需要 BLUETOOTH权限。

    Inherited methods

    From class java.lang.Object
    From interface android.bluetooth.BluetoothProfile

    Constants

    APP_CONFIG_REGISTRATION_FAILURE

    Added in API level 14
    int APP_CONFIG_REGISTRATION_FAILURE

    健康应用配置注册失败

    常数值:1(0x00000001)

    APP_CONFIG_REGISTRATION_SUCCESS

    Added in API level 14
    int APP_CONFIG_REGISTRATION_SUCCESS

    健康应用配置注册成功

    常量值:0(0x00000000)

    APP_CONFIG_UNREGISTRATION_FAILURE

    Added in API level 14
    int APP_CONFIG_UNREGISTRATION_FAILURE

    健康应用程序配置取消注册失败

    常量值:3(0x00000003)

    APP_CONFIG_UNREGISTRATION_SUCCESS

    Added in API level 14
    int APP_CONFIG_UNREGISTRATION_SUCCESS

    健康应用程序配置取消注册成功

    常量值:2(0x00000002)

    CHANNEL_TYPE_RELIABLE

    Added in API level 14
    int CHANNEL_TYPE_RELIABLE

    健康档案 - 使用的频道类型 - 可靠

    常量值:10(0x0000000a)

    CHANNEL_TYPE_STREAMING

    Added in API level 14
    int CHANNEL_TYPE_STREAMING

    健康档案 - 使用的频道类型 - 串流

    常量值:11(0x0000000b)

    SINK_ROLE

    Added in API level 14
    int SINK_ROLE

    Health Profile Sink角色设备与健康设备通话。

    常量值:2(0x00000002)

    SOURCE_ROLE

    Added in API level 14
    int SOURCE_ROLE

    健康档案源角色 - 健康设备。

    常数值:1(0x00000001)

    STATE_CHANNEL_CONNECTED

    Added in API level 14
    int STATE_CHANNEL_CONNECTED

    健康通道连接状态 - 已连接

    常量值:2(0x00000002)

    STATE_CHANNEL_CONNECTING

    Added in API level 14
    int STATE_CHANNEL_CONNECTING

    健康通道连接状态 - 连接

    常数值:1(0x00000001)

    STATE_CHANNEL_DISCONNECTED

    Added in API level 14
    int STATE_CHANNEL_DISCONNECTED

    健康通道连接状态 - 断开连接

    常量值:0(0x00000000)

    STATE_CHANNEL_DISCONNECTING

    Added in API level 14
    int STATE_CHANNEL_DISCONNECTING

    健康通道连接状态 - 断开连接

    常量值:3(0x00000003)

    Public methods

    connectChannelToSource

    Added in API level 14
    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.

    disconnectChannel

    Added in API level 14
    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.

    getConnectedDevices

    Added in API level 14
    List<BluetoothDevice> getConnectedDevices ()

    获取健康档案的连接设备。

    返回处于状态 STATE_CONNECTED的设备 STATE_CONNECTED

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

    Returns
    List<BluetoothDevice> List of devices. The list will be empty on error.

    getConnectionState

    Added in API level 14
    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

    getDevicesMatchingConnectionStates

    Added in API level 14
    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.

    getMainChannelFd

    Added in API level 14
    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.

    registerSinkAppConfiguration

    Added in API level 14
    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.

    unregisterAppConfiguration

    Added in API level 14
    boolean unregisterAppConfiguration (BluetoothHealthAppConfiguration config)

    取消注册已使用 registerSinkAppConfiguration(String, int, BluetoothHealthCallback)注册的应用程序配置

    需要 BLUETOOTH权限。

    Parameters
    config BluetoothHealthAppConfiguration: The health app configuration
    Returns
    boolean Success or failure.
  • Hooray!