Android APIs
public final class

BluetoothHealth

extends Object
implements BluetoothProfile
java.lang.Object
   ↳ android.bluetooth.BluetoothHealth

Class Overview

Public API for Bluetooth Health Profile.

BluetoothHealth is a proxy object for controlling the Bluetooth Service via IPC.

How to connect to a health device which is acting in the source role.

  • 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 Health App Configuration registration failure
    int APP_CONFIG_REGISTRATION_SUCCESS Health App Configuration registration success
    int APP_CONFIG_UNREGISTRATION_FAILURE Health App Configuration un-registration failure
    int APP_CONFIG_UNREGISTRATION_SUCCESS Health App Configuration un-registration success
    int CHANNEL_TYPE_RELIABLE Health Profile - Channel Type used - Reliable
    int CHANNEL_TYPE_STREAMING Health Profile - Channel Type used - Streaming
    int SINK_ROLE Health Profile Sink Role the device talking to the health device.
    int SOURCE_ROLE Health Profile Source Role - the health device.
    int STATE_CHANNEL_CONNECTED Health Channel Connection State - Connected
    int STATE_CHANNEL_CONNECTING Health Channel Connection State - Connecting
    int STATE_CHANNEL_DISCONNECTED Health Channel Connection State - Disconnected
    int STATE_CHANNEL_DISCONNECTING Health Channel Connection State - Disconnecting
    [Expand]
    Inherited Constants
    From interface android.bluetooth.BluetoothProfile
    Public Methods
    boolean connectChannelToSource(BluetoothDevice device, BluetoothHealthAppConfiguration config)
    Connect to a health device which has the SOURCE_ROLE.
    boolean disconnectChannel(BluetoothDevice device, BluetoothHealthAppConfiguration config, int channelId)
    Disconnect a connected health channel.
    List<BluetoothDevice> getConnectedDevices()
    Get connected devices for the health profile.
    int getConnectionState(BluetoothDevice device)
    Get the current connection state of the profile.
    List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states)
    Get a list of devices that match any of the given connection states.
    ParcelFileDescriptor getMainChannelFd(BluetoothDevice device, BluetoothHealthAppConfiguration config)
    Get the file descriptor of the main channel associated with the remote device and application configuration.
    boolean registerSinkAppConfiguration(String name, int dataType, BluetoothHealthCallback callback)
    Register an application configuration that acts as a Health SINK.
    boolean unregisterAppConfiguration(BluetoothHealthAppConfiguration config)
    Unregister an application configuration that has been registered using registerSinkAppConfiguration(String, int, BluetoothHealthCallback)

    Requires BLUETOOTH permission.

    [Expand]
    Inherited Methods
    From class java.lang.Object
    From interface android.bluetooth.BluetoothProfile

    Constants

    public static final int APP_CONFIG_REGISTRATION_FAILURE

    Added in API level 14

    Health App Configuration registration failure

    Constant Value: 1 (0x00000001)

    public static final int APP_CONFIG_REGISTRATION_SUCCESS

    Added in API level 14

    Health App Configuration registration success

    Constant Value: 0 (0x00000000)

    public static final int APP_CONFIG_UNREGISTRATION_FAILURE

    Added in API level 14

    Health App Configuration un-registration failure

    Constant Value: 3 (0x00000003)

    public static final int APP_CONFIG_UNREGISTRATION_SUCCESS

    Added in API level 14

    Health App Configuration un-registration success

    Constant Value: 2 (0x00000002)

    public static final int CHANNEL_TYPE_RELIABLE

    Added in API level 14

    Health Profile - Channel Type used - Reliable

    Constant Value: 10 (0x0000000a)

    public static final int CHANNEL_TYPE_STREAMING

    Added in API level 14

    Health Profile - Channel Type used - Streaming

    Constant Value: 11 (0x0000000b)

    public static final int SINK_ROLE

    Added in API level 14

    Health Profile Sink Role the device talking to the health device.

    Constant Value: 2 (0x00000002)

    public static final int SOURCE_ROLE

    Added in API level 14

    Health Profile Source Role - the health device.

    Constant Value: 1 (0x00000001)

    public static final int STATE_CHANNEL_CONNECTED

    Added in API level 14

    Health Channel Connection State - Connected

    Constant Value: 2 (0x00000002)

    public static final int STATE_CHANNEL_CONNECTING

    Added in API level 14

    Health Channel Connection State - Connecting

    Constant Value: 1 (0x00000001)

    public static final int STATE_CHANNEL_DISCONNECTED

    Added in API level 14

    Health Channel Connection State - Disconnected

    Constant Value: 0 (0x00000000)

    public static final int STATE_CHANNEL_DISCONNECTING

    Added in API level 14

    Health Channel Connection State - Disconnecting

    Constant Value: 3 (0x00000003)

    Public Methods

    public boolean connectChannelToSource (BluetoothDevice device, BluetoothHealthAppConfiguration config)

    Added in API level 14

    Connect to a health device which has the SOURCE_ROLE. This is an asynchronous call. If this function returns true, the callback associated with the application configuration will be called.

    Requires BLUETOOTH permission.

    Parameters
    device The remote Bluetooth device.
    config The application configuration which has been registered using registerSinkAppConfiguration(String, int, BluetoothHealthCallback)
    Returns
    • If true, the callback associated with the application config will be called.

    public boolean disconnectChannel (BluetoothDevice device, BluetoothHealthAppConfiguration config, int channelId)

    Added in API level 14

    Disconnect a connected health channel. This is an asynchronous call. If this function returns true, the callback associated with the application configuration will be called.

    Requires BLUETOOTH permission.

    Parameters
    device The remote Bluetooth device.
    config The application configuration which has been registered using registerSinkAppConfiguration(String, int, BluetoothHealthCallback)
    channelId The channel id associated with the channel
    Returns
    • If true, the callback associated with the application config will be called.

    public List<BluetoothDevice> getConnectedDevices ()

    Added in API level 14

    Get connected devices for the health profile.

    Return the set of devices which are in state STATE_CONNECTED

    Requires BLUETOOTH permission. This is not specific to any application configuration but represents the connection state of the local Bluetooth adapter for this profile. This can be used by applications like status bar which would just like to know the state of the local adapter.

    Returns
    • List of devices. The list will be empty on error.

    public int getConnectionState (BluetoothDevice device)

    Added in API level 14

    Get the current connection state of the profile.

    Requires BLUETOOTH permission. This is not specific to any application configuration but represents the connection state of the local Bluetooth adapter with the remote device. This can be used by applications like status bar which would just like to know the state of the local adapter.

    Parameters
    device Remote bluetooth device.
    Returns

    public List<BluetoothDevice> getDevicesMatchingConnectionStates (int[] states)

    Added in API level 14

    Get a list of devices that match any of the given connection states.

    If none of the devices match any of the given states, an empty list will be returned.

    Requires BLUETOOTH permission. This is not specific to any application configuration but represents the connection state of the local Bluetooth adapter for this profile. This can be used by applications like status bar which would just like to know the state of the local adapter.

    Parameters
    states Array of states. States can be one of STATE_CONNECTED, STATE_CONNECTING, STATE_DISCONNECTED, STATE_DISCONNECTING,
    Returns
    • List of devices. The list will be empty on error.

    public ParcelFileDescriptor getMainChannelFd (BluetoothDevice device, BluetoothHealthAppConfiguration config)

    Added in API level 14

    Get the file descriptor of the main channel associated with the remote device and application configuration.

    Requires BLUETOOTH permission.

    Its the responsibility of the caller to close the ParcelFileDescriptor when done.

    Parameters
    device The remote Bluetooth health device
    config The application configuration
    Returns
    • null on failure, ParcelFileDescriptor on success.

    public boolean registerSinkAppConfiguration (String name, int dataType, BluetoothHealthCallback callback)

    Added in API level 14

    Register an application configuration that acts as a Health SINK. This is the configuration that will be used to communicate with health devices which will act as the SOURCE_ROLE. This is an asynchronous call and so the callback is used to notify success or failure if the function returns true.

    Requires BLUETOOTH permission.

    Parameters
    name The friendly name associated with the application or configuration.
    dataType The dataType of the Source role of Health Profile to which the sink wants to connect to.
    callback A callback to indicate success or failure of the registration and all operations done on this application configuration.
    Returns
    • If true, callback will be called.

    public boolean unregisterAppConfiguration (BluetoothHealthAppConfiguration config)

    Added in API level 14

    Unregister an application configuration that has been registered using registerSinkAppConfiguration(String, int, BluetoothHealthCallback)

    Requires BLUETOOTH permission.

    Parameters
    config The health app configuration
    Returns
    • Success or failure.