public final class BluetoothHealth extends Object implements BluetoothProfile
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.
BluetoothAdapter.getProfileProxy(android.content.Context, android.bluetooth.BluetoothProfile.ServiceListener, int)
to get
the BluetoothHealth proxy object. BluetoothHealth
callback and call
registerSinkAppConfiguration(java.lang.String, int, android.bluetooth.BluetoothHealthCallback)
to register an application
configuration connectChannelToSource(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothHealthAppConfiguration)
. Some
devices will connect the channel automatically. The BluetoothHealth
callback will inform the application of channel state change. disconnectChannel(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothHealthAppConfiguration, int)
and unregister the application configuration calling
unregisterAppConfiguration(android.bluetooth.BluetoothHealthAppConfiguration)
BluetoothProfile.ServiceListener
Modifier and Type | Field and Description |
---|---|
static int |
APP_CONFIG_REGISTRATION_FAILURE
Health App Configuration registration failure
|
static int |
APP_CONFIG_REGISTRATION_SUCCESS
Health App Configuration registration success
|
static int |
APP_CONFIG_UNREGISTRATION_FAILURE
Health App Configuration un-registration failure
|
static int |
APP_CONFIG_UNREGISTRATION_SUCCESS
Health App Configuration un-registration success
|
static int |
CHANNEL_TYPE_ANY |
static int |
CHANNEL_TYPE_RELIABLE
Health Profile - Channel Type used - Reliable
|
static int |
CHANNEL_TYPE_STREAMING
Health Profile - Channel Type used - Streaming
|
static int |
HEALTH_OPERATION_ERROR |
static int |
HEALTH_OPERATION_GENERIC_FAILURE |
static int |
HEALTH_OPERATION_INVALID_ARGS |
static int |
HEALTH_OPERATION_NOT_ALLOWED |
static int |
HEALTH_OPERATION_NOT_FOUND |
static int |
HEALTH_OPERATION_SUCCESS |
static int |
SINK_ROLE
Health Profile Sink Role the device talking to the health device.
|
static int |
SOURCE_ROLE
Health Profile Source Role - the health device.
|
static int |
STATE_CHANNEL_CONNECTED
Health Channel Connection State - Connected
|
static int |
STATE_CHANNEL_CONNECTING
Health Channel Connection State - Connecting
|
static int |
STATE_CHANNEL_DISCONNECTED
Health Channel Connection State - Disconnected
|
static int |
STATE_CHANNEL_DISCONNECTING
Health Channel Connection State - Disconnecting
|
A2DP, EXTRA_PREVIOUS_STATE, EXTRA_STATE, HEADSET, HEALTH, INPUT_DEVICE, PAN, PBAP, PRIORITY_AUTO_CONNECT, PRIORITY_OFF, PRIORITY_ON, PRIORITY_UNDEFINED, STATE_CONNECTED, STATE_CONNECTING, STATE_DISCONNECTED, STATE_DISCONNECTING
Modifier and Type | Method and Description |
---|---|
boolean |
connectChannelToSink(BluetoothDevice device,
BluetoothHealthAppConfiguration config,
int channelType)
Connect to a health device which has the
SINK_ROLE . |
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 |
registerAppConfiguration(String name,
int dataType,
int role,
int channelType,
BluetoothHealthCallback callback)
Register an application configuration that acts as a Health SINK or in a Health
SOURCE role.This is an asynchronous call and so
the callback is used to notify success or failure if the function returns true.
|
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(java.lang.String, int, android.bluetooth.BluetoothHealthCallback) |
public static final int SOURCE_ROLE
public static final int SINK_ROLE
public static final int CHANNEL_TYPE_RELIABLE
public static final int CHANNEL_TYPE_STREAMING
public static final int CHANNEL_TYPE_ANY
public static final int HEALTH_OPERATION_SUCCESS
public static final int HEALTH_OPERATION_ERROR
public static final int HEALTH_OPERATION_INVALID_ARGS
public static final int HEALTH_OPERATION_GENERIC_FAILURE
public static final int HEALTH_OPERATION_NOT_FOUND
public static final int HEALTH_OPERATION_NOT_ALLOWED
public static final int STATE_CHANNEL_DISCONNECTED
public static final int STATE_CHANNEL_CONNECTING
public static final int STATE_CHANNEL_CONNECTED
public static final int STATE_CHANNEL_DISCONNECTING
public static final int APP_CONFIG_REGISTRATION_SUCCESS
public static final int APP_CONFIG_REGISTRATION_FAILURE
public static final int APP_CONFIG_UNREGISTRATION_SUCCESS
public static final int APP_CONFIG_UNREGISTRATION_FAILURE
public boolean registerSinkAppConfiguration(String name, int dataType, BluetoothHealthCallback callback)
SOURCE_ROLE
. This is an asynchronous call and so
the callback is used to notify success or failure if the function returns true.
Requires android.Manifest.permission#BLUETOOTH
permission.
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.public boolean registerAppConfiguration(String name, int dataType, int role, int channelType, BluetoothHealthCallback callback)
Requires android.Manifest.permission#BLUETOOTH
permission.
name
- The friendly name associated with the application or configuration.dataType
- The dataType of the Source role of Health Profile.channelType
- The channel type. Will be one of
CHANNEL_TYPE_RELIABLE
or
CHANNEL_TYPE_STREAMING
callback
- - A callback to indicate success or failure.public boolean unregisterAppConfiguration(BluetoothHealthAppConfiguration config)
registerSinkAppConfiguration(java.lang.String, int, android.bluetooth.BluetoothHealthCallback)
Requires android.Manifest.permission#BLUETOOTH
permission.
config
- The health app configurationpublic boolean connectChannelToSource(BluetoothDevice device, BluetoothHealthAppConfiguration config)
SOURCE_ROLE
.
This is an asynchronous call. If this function returns true, the callback
associated with the application configuration will be called.
Requires android.Manifest.permission#BLUETOOTH
permission.
device
- The remote Bluetooth device.config
- The application configuration which has been registered using
registerSinkAppConfiguration(String, int, BluetoothHealthCallback)
public boolean connectChannelToSink(BluetoothDevice device, BluetoothHealthAppConfiguration config, int channelType)
SINK_ROLE
.
This is an asynchronous call. If this function returns true, the callback
associated with the application configuration will be called.
Requires android.Manifest.permission#BLUETOOTH
permission.
device
- The remote Bluetooth device.config
- The application configuration which has been registered using
registerSinkAppConfiguration(String, int, BluetoothHealthCallback)
public boolean disconnectChannel(BluetoothDevice device, BluetoothHealthAppConfiguration config, int channelId)
Requires android.Manifest.permission#BLUETOOTH
permission.
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 channelpublic ParcelFileDescriptor getMainChannelFd(BluetoothDevice device, BluetoothHealthAppConfiguration config)
Requires android.Manifest.permission#BLUETOOTH
permission.
Its the responsibility of the caller to close the ParcelFileDescriptor when done.
device
- The remote Bluetooth health deviceconfig
- The application configurationpublic int getConnectionState(BluetoothDevice device)
Requires android.Manifest.permission#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.
getConnectionState
in interface BluetoothProfile
device
- Remote bluetooth device.BluetoothProfile.STATE_CONNECTED
, BluetoothProfile.STATE_CONNECTING
,
BluetoothProfile.STATE_DISCONNECTED
, BluetoothProfile.STATE_DISCONNECTING
public List<BluetoothDevice> getConnectedDevices()
Return the set of devices which are in state BluetoothProfile.STATE_CONNECTED
Requires android.Manifest.permission#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.
getConnectedDevices
in interface BluetoothProfile
public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states)
If none of the devices match any of the given states, an empty list will be returned.
Requires android.Manifest.permission#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.
getDevicesMatchingConnectionStates
in interface BluetoothProfile
states
- Array of states. States can be one of
BluetoothProfile.STATE_CONNECTED
, BluetoothProfile.STATE_CONNECTING
,
BluetoothProfile.STATE_DISCONNECTED
, BluetoothProfile.STATE_DISCONNECTING
,