public final class BluetoothInputDevice extends Object implements BluetoothProfile
BluetoothInputDevice is a proxy object for controlling the Bluetooth
Service via IPC. Use BluetoothAdapter.getProfileProxy(android.content.Context, android.bluetooth.BluetoothProfile.ServiceListener, int)
to get
the BluetoothInputDevice proxy object.
Each method is protected with its appropriate permission.
BluetoothProfile.ServiceListener
A2DP, A2DP_SINK, AVRCP_CONTROLLER, EXTRA_PREVIOUS_STATE, EXTRA_STATE, GATT, GATT_SERVER, HEADSET, HEADSET_CLIENT, HEALTH, INPUT_DEVICE, MAP, PAN, PBAP, PBAP_CLIENT, PRIORITY_AUTO_CONNECT, PRIORITY_OFF, PRIORITY_ON, PRIORITY_UNDEFINED, SAP, STATE_CONNECTED, STATE_CONNECTING, STATE_DISCONNECTED, STATE_DISCONNECTING
Modifier and Type | Method and Description |
---|---|
boolean |
connect(BluetoothDevice device)
Initiate connection to a profile of the remote bluetooth device.
|
boolean |
disconnect(BluetoothDevice device)
Initiate disconnection from a profile
This API will return false in scenarios like the profile on the
Bluetooth device is not in connected state etc.
|
List<BluetoothDevice> |
getConnectedDevices()
Get connected devices for this specific profile.
|
int |
getConnectionState(BluetoothDevice device)
Get the current connection state of the profile
Requires
android.Manifest.permission#BLUETOOTH permission. |
List<BluetoothDevice> |
getDevicesMatchingConnectionStates(int[] states)
Get a list of devices that match any of the given connection
states.
|
int |
getPriority(BluetoothDevice device)
Get the priority of the profile.
|
boolean |
getProtocolMode(BluetoothDevice device)
Send Get_Protocol_Mode command to the connected HID input device.
|
boolean |
getReport(BluetoothDevice device,
byte reportType,
byte reportId,
int bufferSize)
Send Get_Report command to the connected HID input device.
|
boolean |
sendData(BluetoothDevice device,
String report)
Send Send_Data command to the connected HID input device.
|
boolean |
setPriority(BluetoothDevice device,
int priority)
Set priority of the profile
The device should already be paired.
|
boolean |
setProtocolMode(BluetoothDevice device,
int protocolMode)
Send Set_Protocol_Mode command to the connected HID input device.
|
boolean |
setReport(BluetoothDevice device,
byte reportType,
String report)
Send Set_Report command to the connected HID input device.
|
boolean |
virtualUnplug(BluetoothDevice device)
Initiate virtual unplug for a HID input device.
|
public static final String ACTION_CONNECTION_STATE_CHANGED
This intent will have 3 extras:
BluetoothProfile.EXTRA_STATE
- The current state of the profile. BluetoothProfile.EXTRA_PREVIOUS_STATE
- The previous state of the profile.BluetoothDevice.EXTRA_DEVICE
- The remote device. BluetoothProfile.EXTRA_STATE
or BluetoothProfile.EXTRA_PREVIOUS_STATE
can be any of
BluetoothProfile.STATE_DISCONNECTED
, BluetoothProfile.STATE_CONNECTING
,
BluetoothProfile.STATE_CONNECTED
, BluetoothProfile.STATE_DISCONNECTING
.
Requires android.Manifest.permission#BLUETOOTH
permission to
receive.
public static final String ACTION_PROTOCOL_MODE_CHANGED
public static final String ACTION_HANDSHAKE
public static final String ACTION_REPORT
public static final String ACTION_VIRTUAL_UNPLUG_STATUS
public static final int INPUT_DISCONNECT_FAILED_NOT_CONNECTED
public static final int INPUT_CONNECT_FAILED_ALREADY_CONNECTED
public static final int INPUT_CONNECT_FAILED_ATTEMPT_FAILED
public static final int INPUT_OPERATION_GENERIC_FAILURE
public static final int INPUT_OPERATION_SUCCESS
public static final int PROTOCOL_REPORT_MODE
public static final int PROTOCOL_BOOT_MODE
public static final int PROTOCOL_UNSUPPORTED_MODE
public static final byte REPORT_TYPE_INPUT
public static final byte REPORT_TYPE_OUTPUT
public static final byte REPORT_TYPE_FEATURE
public static final int VIRTUAL_UNPLUG_STATUS_SUCCESS
public static final int VIRTUAL_UNPLUG_STATUS_FAIL
public static final String EXTRA_PROTOCOL_MODE
public static final String EXTRA_REPORT_TYPE
public static final String EXTRA_REPORT_ID
public static final String EXTRA_REPORT_BUFFER_SIZE
public static final String EXTRA_REPORT
public static final String EXTRA_STATUS
public static final String EXTRA_VIRTUAL_UNPLUG_STATUS
public boolean connect(BluetoothDevice device)
The system supports connection to multiple input devices.
This API returns false in scenarios like the profile on the device is already connected or Bluetooth is not turned on. When this API returns true, it is guaranteed that connection state intent for the profile will be broadcasted with the state. Users can get the connection state of the profile from this intent.
Requires android.Manifest.permission#BLUETOOTH_ADMIN
permission.
device
- Remote Bluetooth Devicepublic boolean disconnect(BluetoothDevice device)
This API will return false in scenarios like the profile on the Bluetooth device is not in connected state etc. When this API returns, true, it is guaranteed that the connection state change intent will be broadcasted with the state. Users can get the disconnection state of the profile from this intent.
If the disconnection is initiated by a remote device, the state
will transition from BluetoothProfile.STATE_CONNECTED
to
BluetoothProfile.STATE_DISCONNECTED
. If the disconnect is initiated by the
host (local) device the state will transition from
BluetoothProfile.STATE_CONNECTED
to state BluetoothProfile.STATE_DISCONNECTING
to
state BluetoothProfile.STATE_DISCONNECTED
. The transition to
BluetoothProfile.STATE_DISCONNECTING
can be used to distinguish between the
two scenarios.
Requires android.Manifest.permission#BLUETOOTH_ADMIN
permission.
device
- Remote Bluetooth Devicepublic List<BluetoothDevice> getConnectedDevices()
Return the set of devices which are in state BluetoothProfile.STATE_CONNECTED
Requires android.Manifest.permission#BLUETOOTH
permission.
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.
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
,public int getConnectionState(BluetoothDevice device)
Requires android.Manifest.permission#BLUETOOTH
permission.
getConnectionState
in interface BluetoothProfile
device
- Remote bluetooth device.BluetoothProfile.STATE_CONNECTED
, BluetoothProfile.STATE_CONNECTING
,
BluetoothProfile.STATE_DISCONNECTED
, BluetoothProfile.STATE_DISCONNECTING
public boolean setPriority(BluetoothDevice device, int priority)
The device should already be paired.
Priority can be one of BluetoothProfile.PRIORITY_ON
or
BluetoothProfile.PRIORITY_OFF
,
Requires android.Manifest.permission#BLUETOOTH_ADMIN
permission.
device
- Paired bluetooth devicepriority
- public int getPriority(BluetoothDevice device)
The priority can be any of:
BluetoothProfile.PRIORITY_AUTO_CONNECT
, BluetoothProfile.PRIORITY_OFF
,
BluetoothProfile.PRIORITY_ON
, BluetoothProfile.PRIORITY_UNDEFINED
Requires android.Manifest.permission#BLUETOOTH
permission.
device
- Bluetooth devicepublic boolean virtualUnplug(BluetoothDevice device)
Requires android.Manifest.permission#BLUETOOTH_ADMIN
permission.
device
- Remote Bluetooth Devicepublic boolean getProtocolMode(BluetoothDevice device)
Requires android.Manifest.permission#BLUETOOTH_ADMIN
permission.
device
- Remote Bluetooth Devicepublic boolean setProtocolMode(BluetoothDevice device, int protocolMode)
Requires android.Manifest.permission#BLUETOOTH_ADMIN
permission.
device
- Remote Bluetooth Devicepublic boolean getReport(BluetoothDevice device, byte reportType, byte reportId, int bufferSize)
Requires android.Manifest.permission#BLUETOOTH_ADMIN
permission.
device
- Remote Bluetooth DevicereportType
- Report typereportId
- Report IDbufferSize
- Report receiving buffer sizepublic boolean setReport(BluetoothDevice device, byte reportType, String report)
Requires android.Manifest.permission#BLUETOOTH_ADMIN
permission.
device
- Remote Bluetooth DevicereportType
- Report typereport
- Report receiving buffer sizepublic boolean sendData(BluetoothDevice device, String report)
Requires android.Manifest.permission#BLUETOOTH_ADMIN
permission.
device
- Remote Bluetooth Devicereport
- Report to send