public static enum UhOhListener.UhOh extends java.lang.Enum<UhOhListener.UhOh>
Exception
but they can be so common
that using Exception
would render this library unusable without a rat's nest of try/catches.
Instead you implement UhOhListener
to receive them. Each UhOhListener.UhOh
has a getRemedy()
that suggests what might be done about it.Enum Constant and Description |
---|
BOND_TIMED_OUT
A
BleTask.BOND operation timed out. |
CANNOT_DISABLE_BLUETOOTH
BluetoothAdapter.disable() , through BleManager.turnOff() , is failing to complete. |
CANNOT_ENABLE_BLUETOOTH
BluetoothAdapter.enable() , through BleManager.turnOn() , is failing to complete. |
CLASSIC_DISCOVERY_FAILED
BluetoothAdapter.startLeScan(BluetoothAdapter.LeScanCallback) failed and BleManagerConfig.revertToClassicDiscoveryIfNeeded is true
so we try BluetoothAdapter.startDiscovery() but that also fails...fun! |
CONCURRENT_EXCEPTION
Occasionally, when trying to get the native GattService, android will throw a ConcurrentModificationException.
|
CONNECTED_WITHOUT_EVER_CONNECTING
BluetoothGatt.getConnectionState(BluetoothDevice) says we're connected but we never tried to connect in the first place. |
CONNECTION_STILL_ALIVE
This happens when you first bond to a peripheral.
|
DEAD_OBJECT_EXCEPTION
Similar in concept to
RANDOM_EXCEPTION but used when DeadObjectException is thrown. |
DUPLICATE_SERVICE_FOUND
A
BluetoothGatt.discoverServices() operation returned two duplicate services. |
INCONSISTENT_NATIVE_BLE_STATE
When the underlying stack meets a race condition where
BluetoothAdapter.getState() does not
match the value provided through BluetoothAdapter.ACTION_STATE_CHANGED with BluetoothAdapter.EXTRA_STATE . |
INCONSISTENT_NATIVE_DEVICE_STATE
This can be thrown when the underlying state from
BluetoothManager.getConnectionState(BluetoothDevice, int) does not match
the apparent condition of the device (for instance, you perform a scan, then try to connect to a device, but it reports as being connected...in this case, it cannot
be connected, AND advertising). |
OLD_DUPLICATE_SERVICE_FOUND
A
BluetoothGatt.discoverServices() operation returned a service instance that we already received before
after disconnecting and reconnecting. |
PHYSICAL_LAYER_FAILURE
This happens if setting the physical layer fails while connecting (bluetooth 5 features).
|
RANDOM_EXCEPTION
The underlying native BLE stack enjoys surprising you with random exceptions.
|
READ_RETURNED_NULL
A
BleDevice.read(java.util.UUID, ReadWriteListener) returned with a null
characteristic value. |
READ_TIMED_OUT
A
BleDevice.read(java.util.UUID, ReadWriteListener)
took longer than timeout set by BleNodeConfig.taskTimeoutRequestFilter . |
SERVICE_DISCOVERY_IMMEDIATELY_FAILED
BluetoothGatt.discoverServices() failed right off the bat and returned false. |
SETUP_HELPER_DIALOG_ERROR
This can be thrown when there is a WindowManagerBadTokenException when trying to display a dialog
The exception is thrown when the activity has finished but the dialog is shown anyway.
|
START_BLE_SCAN_FAILED
BluetoothAdapter.startLeScan(BluetoothAdapter.LeScanCallback) failed and BleManagerConfig.revertToClassicDiscoveryIfNeeded is false . |
START_BLE_SCAN_FAILED__USING_CLASSIC
BluetoothAdapter.startLeScan(BluetoothAdapter.LeScanCallback) failed for an unknown reason. |
UNKNOWN_BLE_ERROR
Just a blanket case for when the library has to completely shrug its shoulders.
|
WRITE_MTU_TEST_TIMED_OUT
Similar to
WRITE_TIMED_OUT , only used to signify when testing a new MTU size, and it times out. |
WRITE_TIMED_OUT
Similar to
READ_TIMED_OUT but for BleDevice.write(java.util.UUID, byte[]) . |
Modifier and Type | Method and Description |
---|---|
UhOhListener.Remedy |
getRemedy()
Returns the
UhOhListener.Remedy for this UhOhListener.UhOh . |
static UhOhListener.UhOh |
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.
|
static UhOhListener.UhOh[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final UhOhListener.UhOh CONNECTION_STILL_ALIVE
UhOhListener.Remedy.RECYCLE_CONNECTION
public static final UhOhListener.UhOh BOND_TIMED_OUT
BleTask.BOND
operation timed out. This can happen a lot with the Galaxy Tab 4, and doing BleManager.reset()
seems to fix it.
SweetBlue does as much as it can to work around the issue that causes bond timeouts, but some might still slip through.public static final UhOhListener.UhOh READ_TIMED_OUT
BleDevice.read(java.util.UUID, ReadWriteListener)
took longer than timeout set by BleNodeConfig.taskTimeoutRequestFilter
.
You will also get a ReadWriteListener.ReadWriteEvent
with ReadWriteListener.Status.TIMED_OUT
but a timeout is a sort of fringe case that should not regularly happen.public static final UhOhListener.UhOh READ_RETURNED_NULL
BleDevice.read(java.util.UUID, ReadWriteListener)
returned with a null
characteristic value. The null
value will end up as an empty array in ReadWriteListener.ReadWriteEvent.data()
so app-land doesn't have to do any special null
handling.public static final UhOhListener.UhOh WRITE_TIMED_OUT
READ_TIMED_OUT
but for BleDevice.write(java.util.UUID, byte[])
.public static final UhOhListener.UhOh WRITE_MTU_TEST_TIMED_OUT
WRITE_TIMED_OUT
, only used to signify when testing a new MTU size, and it times out. This usually means the android device
has a bug where it says the MTU size has changed, but can't write the MTU size amount (OnePlus2, Moto X Pure). In this case, SweetBlue will disconnect
the device, as no other reads/writes will work once this happens.public static final UhOhListener.UhOh INCONSISTENT_NATIVE_BLE_STATE
BluetoothAdapter.getState()
does not
match the value provided through BluetoothAdapter.ACTION_STATE_CHANGED
with BluetoothAdapter.EXTRA_STATE
.public static final UhOhListener.UhOh DUPLICATE_SERVICE_FOUND
BluetoothGatt.discoverServices()
operation returned two duplicate services. Not the same instance
necessarily but the same UUID.public static final UhOhListener.UhOh OLD_DUPLICATE_SERVICE_FOUND
BluetoothGatt.discoverServices()
operation returned a service instance that we already received before
after disconnecting and reconnecting.public static final UhOhListener.UhOh START_BLE_SCAN_FAILED__USING_CLASSIC
BluetoothAdapter.startLeScan(BluetoothAdapter.LeScanCallback)
failed for an unknown reason. The library is now using
BluetoothAdapter.startDiscovery()
instead.public static final UhOhListener.UhOh CONNECTED_WITHOUT_EVER_CONNECTING
BluetoothGatt.getConnectionState(BluetoothDevice)
says we're connected but we never tried to connect in the first place.
My theory is that this can happen on some phones when you quickly restart the app and the stack doesn't have
a chance to disconnect from the device entirely.public static final UhOhListener.UhOh DEAD_OBJECT_EXCEPTION
RANDOM_EXCEPTION
but used when DeadObjectException
is thrown.public static final UhOhListener.UhOh RANDOM_EXCEPTION
UhOhListener.UhOh
is dispatched.public static final UhOhListener.UhOh CONCURRENT_EXCEPTION
public static final UhOhListener.UhOh PHYSICAL_LAYER_FAILURE
BleDevice.setPhyOptions(Phy, ReadWriteListener)
, or BleDevice.readPhyOptions(ReadWriteListener)
manually.public static final UhOhListener.UhOh START_BLE_SCAN_FAILED
BluetoothAdapter.startLeScan(BluetoothAdapter.LeScanCallback)
failed and BleManagerConfig.revertToClassicDiscoveryIfNeeded
is false
.public static final UhOhListener.UhOh CLASSIC_DISCOVERY_FAILED
BluetoothAdapter.startLeScan(BluetoothAdapter.LeScanCallback)
failed and BleManagerConfig.revertToClassicDiscoveryIfNeeded
is true
so we try BluetoothAdapter.startDiscovery()
but that also fails...fun!public static final UhOhListener.UhOh SERVICE_DISCOVERY_IMMEDIATELY_FAILED
BluetoothGatt.discoverServices()
failed right off the bat and returned false.public static final UhOhListener.UhOh CANNOT_DISABLE_BLUETOOTH
BluetoothAdapter.disable()
, through BleManager.turnOff()
, is failing to complete.
We always end up back at BluetoothAdapter.STATE_ON
.public static final UhOhListener.UhOh CANNOT_ENABLE_BLUETOOTH
BluetoothAdapter.enable()
, through BleManager.turnOn()
, is failing to complete.
We always end up back at BluetoothAdapter.STATE_OFF
. Opposite problem of CANNOT_DISABLE_BLUETOOTH
public static final UhOhListener.UhOh INCONSISTENT_NATIVE_DEVICE_STATE
BluetoothManager.getConnectionState(BluetoothDevice, int)
does not match
the apparent condition of the device (for instance, you perform a scan, then try to connect to a device, but it reports as being connected...in this case, it cannot
be connected, AND advertising). It seems the values from this method are cached, so sometimes this cache gets "stuck" in the connected state. In this case, it may
be best to clear cache of the Bluetooth app (Sometimes called Bluetooth Cache).public static final UhOhListener.UhOh UNKNOWN_BLE_ERROR
public static final UhOhListener.UhOh SETUP_HELPER_DIALOG_ERROR
public static UhOhListener.UhOh[] values()
for (UhOhListener.UhOh c : UhOhListener.UhOh.values()) System.out.println(c);
public static UhOhListener.UhOh valueOf(java.lang.String name)
name
- the name of the enum constant to be returned.java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is nullpublic UhOhListener.Remedy getRemedy()
UhOhListener.Remedy
for this UhOhListener.UhOh
.