Package org.robolectric.shadows
Class ShadowBluetoothHeadset
java.lang.Object
org.robolectric.shadows.ShadowBluetoothHeadset
@NotThreadSafe
@Implements(android.bluetooth.BluetoothHeadset.class)
public class ShadowBluetoothHeadset
extends Object
Shadow for
BluetoothHeadset-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConnectedDevice(BluetoothDevice device) Adds the given BluetoothDevice to the shadow's list of "connected devices"voidaddDevice(BluetoothDevice bluetoothDevice, int connectionState) Adds the provided BluetoothDevice to the shadow profile's device list with an associated connectionState.protected booleanconnect(BluetoothDevice device) Overrides behavior ofconnect(android.bluetooth.BluetoothDevice).protected booleandisconnect(BluetoothDevice device) Overrides behavior ofdisconnect(android.bluetooth.BluetoothDevice).protected BluetoothDeviceprotected List<BluetoothDevice>Overrides behavior ofgetConnectedDevices().protected intgetConnectionState(BluetoothDevice device) Overrides behavior ofgetConnectionState(android.bluetooth.BluetoothDevice).protected List<BluetoothDevice>getDevicesMatchingConnectionStates(int[] states) protected booleanisAudioConnected(BluetoothDevice bluetoothDevice) protected booleanChecks whether the headset supports voice recognition.voidremoveDevice(BluetoothDevice bluetoothDevice) Remove the given BluetoothDevice from the shadow profile's device listprotected booleansendVendorSpecificResultCode(BluetoothDevice device, String command, String arg) protected booleansetActiveDevice(BluetoothDevice bluetoothDevice) voidsetAllowsSendVendorSpecificResultCode(boolean allowsSendVendorSpecificResultCode) voidsetVoiceRecognitionSupported(boolean supported) Sets whether the headset supports voice recognition.protected booleanstartVoiceRecognition(BluetoothDevice bluetoothDevice) Overrides behavior ofstartVoiceRecognition(android.bluetooth.BluetoothDevice).protected booleanstopVoiceRecognition(BluetoothDevice bluetoothDevice) Overrides the behavior ofstopVoiceRecognition(android.bluetooth.BluetoothDevice).
-
Constructor Details
-
ShadowBluetoothHeadset
public ShadowBluetoothHeadset()
-
-
Method Details
-
getConnectedDevices
Overrides behavior ofgetConnectedDevices(). Returns list of devices that is set up by call(s) toaddConnectedDevice(android.bluetooth.BluetoothDevice)orconnect(android.bluetooth.BluetoothDevice). Returns an empty list by default. -
addConnectedDevice
Adds the given BluetoothDevice to the shadow's list of "connected devices" -
addDevice
Adds the provided BluetoothDevice to the shadow profile's device list with an associated connectionState. The provided connection state will be returned bygetConnectionState(android.bluetooth.BluetoothDevice). -
removeDevice
Remove the given BluetoothDevice from the shadow profile's device list -
getConnectionState
Overrides behavior ofgetConnectionState(android.bluetooth.BluetoothDevice).- Returns:
BluetoothProfile.STATE_CONNECTEDif the given device has been previously added by a call toaddConnectedDevice(android.bluetooth.BluetoothDevice)orconnect(android.bluetooth.BluetoothDevice), andBluetoothProfile.STATE_DISCONNECTEDotherwise.
-
getDevicesMatchingConnectionStates
-
connect
Overrides behavior ofconnect(android.bluetooth.BluetoothDevice). Returnstrueand addsdeviceto the shadow profile's connected device list ifdeviceis currently disconnected, and returnsfalseotherwise. -
disconnect
Overrides behavior ofdisconnect(android.bluetooth.BluetoothDevice). Returnstrueand removesdevicefrom the shadow profile's connected device list ifdeviceis currently connected, and returnsfalseotherwise. -
startVoiceRecognition
Overrides behavior ofstartVoiceRecognition(android.bluetooth.BluetoothDevice). Returns false if 'bluetoothDevice' is null or voice recognition is already started. Users can listen toACTION_AUDIO_STATE_CHANGED. If this function returns true, this intent will be broadcasted once withBluetoothProfile.EXTRA_STATEset toSTATE_AUDIO_CONNECTINGand once set toSTATE_AUDIO_CONNECTED. -
stopVoiceRecognition
Overrides the behavior ofstopVoiceRecognition(android.bluetooth.BluetoothDevice). Returns false if voice recognition was not started or voice recognition has already ended on this headset. If this function returns true,ACTION_AUDIO_STATE_CHANGEDintent is broadcasted withBluetoothProfile.EXTRA_STATEset toSTATE_DISCONNECTED. -
isAudioConnected
-
sendVendorSpecificResultCode
@Implementation protected boolean sendVendorSpecificResultCode(BluetoothDevice device, String command, String arg) Overrides behavior ofsendVendorSpecificResultCode(android.bluetooth.BluetoothDevice,java.lang.String,java.lang.String).- Returns:
- 'true' only if the given device has been previously added by a call to
addConnectedDevice(android.bluetooth.BluetoothDevice)orconnect(android.bluetooth.BluetoothDevice), andsetAllowsSendVendorSpecificResultCode(boolean)has not been called with 'false' argument. - Throws:
IllegalArgumentException- if 'command' argument is null, per Android API
-
getActiveDevice
-
setActiveDevice
@Implementation(minSdk=28) protected boolean setActiveDevice(@Nullable BluetoothDevice bluetoothDevice) -
setVoiceRecognitionSupported
public void setVoiceRecognitionSupported(boolean supported) Sets whether the headset supports voice recognition.By default voice recognition is supported.
-
isVoiceRecognitionSupported
Checks whether the headset supports voice recognition.- See Also:
-
setAllowsSendVendorSpecificResultCode
public void setAllowsSendVendorSpecificResultCode(boolean allowsSendVendorSpecificResultCode) Affects the behavior ofBluetoothHeadset.sendVendorSpecificResultCode(android.bluetooth.BluetoothDevice, java.lang.String, java.lang.String)- Parameters:
allowsSendVendorSpecificResultCode- can be set to 'false' to simulate the situation where the system is unable to send vendor-specific result codes to a device
-