public final class RxBleManager
extends java.lang.Object
BleManager
directly. The observe methods in this class
set listeners in the BleManager
instance, so it's best not to use it as much as possible. You must remember to put your api key
into a file called sweetblue_api_key.txt, and place it in your assets folder. As an alternate, you can use createInstance(Context, RxBleManagerConfig, String)
to set your api key.Modifier and Type | Field and Description |
---|---|
static RxBleDeviceTransformer |
BLE_DEVICE_TRANSFORMER
Convenience class for converting a
BleDevice instance to an instance of RxBleDevice via RxJava |
static RxBleServerTransformer |
BLE_SERVER_TRANSFORMER
Convenience class for converting a
BleServer instance to an instance of RxBleServer via RxJava |
Modifier and Type | Method and Description |
---|---|
boolean |
ASSERT(boolean condition)
Fires a callback to
AssertListener if condition is false. |
boolean |
ASSERT(boolean condition,
java.lang.String message)
Same as
ASSERT(boolean) but with an added message. |
void |
clearQueue()
This method will clear the task queue of all tasks.
|
void |
clearSharedPreferences()
Clears all data currently being held in
SharedPreferences for all devices. |
void |
clearSharedPreferences(RxBleDevice device)
Convenience forwarding of
clearSharedPreferences(String) . |
void |
clearSharedPreferences(java.lang.String macAddress)
Clears all data currently being held in
SharedPreferences for a particular device. |
static RxBleManager |
createInstance(android.content.Context context,
RxBleManagerConfig config,
java.lang.String apiKey)
Creates a new instance of
RxBleManager , if it does not already exist. |
void |
disconnectAll_remote()
Same as
disconnectAll() but drills down to RxBleDevice.disconnect_remote() instead. |
void |
disconnectAll()
Disconnects all devices that are
BleDeviceState.BLE_CONNECTED . |
static RxBleManager |
get(android.content.Context context)
Get the instance of
RxBleManager . |
static RxBleManager |
get(android.content.Context context,
RxBleManagerConfig config)
Get the instance of
RxBleManager . |
android.content.Context |
getApplicationContext()
Returns the
Application provided to the constructor. |
BleManager |
getBleManager() |
RxBleManagerConfig |
getConfigClone() |
RxBleDevice |
getDevice(BleDeviceState state)
Rx-ified version of
BleManager.getDevice(BleDeviceState) . |
BleDevice |
getDevice(int mask_BleDeviceState)
Rx-ified version of
BleManager.getDevice(int) . |
BleDevice |
getDevice(java.lang.Object... query)
Rx-ified version of
BleManager.getDevice(Object...) . |
RxBleDevice |
getDevice(java.lang.String macAddress)
Rx-ified version of
BleManager.getDevice(String) . |
int |
getDeviceCount()
Returns the total number of devices this manager is...managing.
|
int |
getDeviceCount(BleDeviceState state)
Returns the number of devices that are in the current state.
|
int |
getDeviceCount(java.lang.Object... query)
Returns the number of devices that match the given query.
|
<any> |
getDevices_bonded()
Rx-ified version of
BleManager.getDevices_bonded() . |
<any> |
getDevices_previouslyConnected()
Returns an
Observable which emits the macAddresses of all devices that we know about from both
current and previous app sessions. |
<any> |
getDevices_sorted()
Returns an
Observable that emits all RxBleDevice s managed by the library. |
<any> |
getDevices()
Returns an
Observable that emits all RxBleDevice s managed by the library. |
android.bluetooth.BluetoothManager |
getNative()
Returns the native manager.
|
android.bluetooth.BluetoothAdapter |
getNativeAdapter()
Returns the native bluetooth adapter.
|
RxBleServer |
getServer()
Same as
getServer(IncomingListener, GattDatabase, AddServiceListener) , which passes null for all arguments. |
RxBleServer |
getServer(IncomingListener listener,
GattDatabase db,
AddServiceListener addListener)
Rx-ified version of
BleManager.getServer(IncomingListener, GattDatabase, AddServiceListener) . |
int |
getStateMask()
Returns the abstracted bitwise state mask representation of
BleManagerState for the manager instance. |
Interval |
getTimeInState(BleManagerState state)
See similar comment for
RxBleDevice.getTimeInState(BleDeviceState) . |
boolean |
hasDevice(BleDevice device)
Calls
hasDevice(String) . |
boolean |
hasDevice(BleDeviceState state)
Returns true if we have a device in the given state.
|
boolean |
hasDevice(int mask_BleDeviceState)
Returns
true if there is any BleDevice for which BleDevice.isAny(int) with the given mask returns true . |
boolean |
hasDevice(java.lang.Object... query)
Returns true if we have a device that matches the given query.
|
boolean |
hasDevice(java.lang.String macAddress)
Shortcut for checking if
getDevice(String) returns BleDevice.NULL . |
boolean |
hasDevices()
Returns whether we have any devices.
|
boolean |
is(BleManagerState state)
Returns whether the manager is in the provided state.
|
boolean |
isAdvertisingSupported()
Checks to see if the device supports advertising BLE services.
|
boolean |
isAdvertisingSupportedByAndroidVersion()
Checks to see if the device is running an Android OS which supports
advertising.
|
boolean |
isAdvertisingSupportedByChipset()
Checks to see if the device supports advertising.
|
boolean |
isAll(BleManagerState... states)
Returns whether the manager is in all of the provided states.
|
boolean |
isAll(int mask_BleManagerState)
Returns
true if there is complete bitwise overlap between the provided value and getStateMask() . |
boolean |
isAny(BleManagerState... states)
Returns whether the manager is in any of the provided states.
|
boolean |
isAny(int mask_BleManagerState)
Returns
true if there is partial bitwise overlap between the provided value and getStateMask() . |
boolean |
isBleSupported()
Checks the underlying stack to see if BLE is supported on the phone.
|
boolean |
isBluetooth5HighSpeedSupported()
Returns
true if the android device supports the high speed feature of Bluetooth 5 (2x the speed of Bluetooth 4.x). |
boolean |
isBluetooth5LongRangeSupported()
Returns
true if the android device supports the bluetooth 5 feature of long range (up to 4x the range of Bluetooth 4.x). |
boolean |
isBluetooth5Supported()
Convenience method to check if the android device supports bluetooth 5 in any way.
|
boolean |
isBluetooth5SupportedByAndroidVersion()
Returns
true if the android device is running an android OS version which supports Bluetooth 5 features. |
boolean |
isForegrounded()
Returns this manager's knowledge of the app's foreground state.
|
boolean |
isLocationEnabledForScanning_byManifestPermissions()
Returns
true if you're either pre-Android-M, or app has permission for either Manifest.permission.ACCESS_COARSE_LOCATION
or Manifest.permission.ACCESS_FINE_LOCATION in your AndroidManifest.xml, false otherwise. |
boolean |
isLocationEnabledForScanning_byOsServices()
Returns
true if you're either pre-Android-M, or location services are enabled, the same is if you go to the Android Settings app
and manually toggle Location ON/OFF. |
boolean |
isLocationEnabledForScanning_byRuntimePermissions()
Returns
true if you're either pre-Android-M, or app has runtime permissions enabled by checking
ContextCompat.checkSelfPermission(android.content.Context, java.lang.String)
See more information at https://developer.android.com/training/permissions/index.html. |
boolean |
isLocationEnabledForScanning()
Returns
true if location is enabled to a degree that allows scanning on Build.VERSION_CODES.M and above. |
boolean |
isScanning()
Convenience method which reports
true if the BleManager is in any of the following states: BleManagerState.SCANNING , BleManagerState.SCANNING_PAUSED , BleManagerState.BOOST_SCANNING , or BleManagerState.STARTING_SCAN |
boolean |
isScanningReady()
Tells you whether a call to
scan(ScanOptions) , will succeed or not. |
RxBleDevice |
newDevice(java.lang.String macAddress)
Rx-ified version of
BleManager.newDevice(String) . |
RxBleDevice |
newDevice(java.lang.String macAddress,
BleManagerConfig config)
Rx-ified version of
BleManager.newDevice(String, BleDeviceConfig) . |
RxBleDevice |
newDevice(java.lang.String macAddress,
java.lang.String name)
Rx-ified version of
BleManager.newDevice(String, String) . |
RxBleDevice |
newDevice(java.lang.String macAddress,
java.lang.String name,
BleDeviceConfig config)
Rx-ified version of
BleManager.newDevice(String, String, BleDeviceConfig) . |
HistoricalData |
newHistoricalData(byte[] data,
EpochTime epochTime)
Returns a new
HistoricalData instance using
BleNodeConfig.historicalDataFactory if available. |
HistoricalData |
newHistoricalData(byte[] data,
EpochTime epochTime,
java.lang.String macAddress)
Same as
newHistoricalData(byte[], EpochTime) but tries to use
BleNode.newHistoricalData(byte[], EpochTime) if we have a device
matching the given mac address. |
void |
nukeBle()
Similar to
BleManager.reset() , only this also calls the factoryReset method hidden in BluetoothAdapter after turning
off BLE, and running the crash resolver. |
void |
nukeBle(ResetListener resetListener)
Similar to
BleManager.reset(ResetListener) , only this also calls the factoryReset method hidden in BluetoothAdapter after turning
off BLE, and running the crash resolver. |
<any> |
observeAdvertisingEvents()
Returns a
Flowable which emits RxAdvertisingEvent when any AdvertisingListener.AdvertisingEvent s
are posted by the library. |
<any> |
observeAssertEvents()
Returns a
Flowable which emits RxAssertEvent when any AssertListener.AssertEvent s
are posted by the library. |
<any> |
observeBondEvents()
Returns a
Flowable which emits RxBondEvent when any BondListener.BondEvent s
for all RxBleDevice s are posted by the library. |
<any> |
observeDeviceConnectEvents()
Returns a
Flowable which emits RxDeviceConnectEvent when any RxBleDevice gets connected (or fails to). |
<any> |
observeDeviceStateEvents()
|
<any> |
observeDiscoveryEvents()
Returns a
Flowable which emits RxDiscoveryEvent whenever a device is DiscoveryListener.LifeCycle.DISCOVERED , DiscoveryListener.LifeCycle.REDISCOVERED ,
or DiscoveryListener.LifeCycle.UNDISCOVERED . |
<any> |
observeHistoricalDataLoadEvents()
Returns a
Flowable which emits RxHistoricalDataLoadEvent when any HistoricalDataLoadListener.HistoricalDataLoadEvent s
for all RxBleDevice s are posted by the library. |
<any> |
observeMgrStateEvents()
|
<any> |
observeNotificationEvents()
Returns a
Flowable which emits RxNotificationEvent when any NotificationListener.NotificationEvent s
for all RxBleDevice s are posted by the library. |
<any> |
observeOutgoingEvents()
Returns a
Flowable which emits RxOutgoingEvent when any OutgoingListener.OutgoingEvent s
are posted by the library. |
<any> |
observeReadWriteEvents()
Returns a
Flowable which emits RxReadWriteEvent when any ReadWriteListener.ReadWriteEvent s
for all RxBleDevice s are posted by the library. |
<any> |
observeServerStateEvents()
Returns a
Flowable which emits RxServerStateEvent when any ServerStateListener.StateEvent s
are posted by the library. |
<any> |
observeServiceAddEvents()
Returns a
Flowable which emits RxServiceAddEvent when any AddServiceListener.ServiceAddEvent s
are posted by the library. |
<any> |
observeUhOhEvents()
|
void |
onPause()
It's generally recommended to call this in your override of
Activity.onPause() for each Activity
in your application. |
void |
onResume()
Opposite of
onPause() , to be called from your override of Activity.onResume() for each Activity
in your application. |
void |
popWakeLock()
Opposite of
pushWakeLock() , eventually calls PowerManager.WakeLock.release() . |
void |
pushWakeLock()
Requires the
Manifest.permission.WAKE_LOCK permission. |
void |
removeAllDevicesFromCache()
Removes all
RxBleDevice s from SweetBlue's internal device cache list. |
void |
removeDeviceFromCache(RxBleDevice device)
Removes the given
RxBleDevice from SweetBlue's internal device cache list. |
void |
reset()
This is essentially a big red reset button for the Bluetooth stack.
|
void |
reset(ResetListener listener)
Same as
reset() but with a convenience callback for when the reset is
completed and the native BLE stack is (should be) back to normal. |
<any> |
scan_onlyNew(ScanOptions options)
Returns a
Flowable which kicks off a scan using the provided ScanOptions once subscribed to. |
<any> |
scan()
Overload of
scan(ScanOptions) , which uses a default instance of ScanOptions . |
<any> |
scan(ScanOptions options)
Returns an
Observable which kicks off a scan using the provided ScanOptions once subscribed to. |
void |
setConfig(RxBleManagerConfig config) |
void |
shutdown()
Disconnects all devices, shuts down the BleManager, and it's backing thread, and unregisters any receivers that may be in use.
|
void |
stopAllScanning()
Deprecated.
use
stopScan() or stopScan(ScanFilter) instead.
This method will be removed in v3.1.
Convenience that will call both BleManager.stopPeriodicScan() and BleManager.stopScan() for you. This is here as a stop-gap
in the off chance the scan doesn't stop when you dispose the Flowable returned from scan(ScanOptions) . |
void |
stopScan()
|
void |
stopScan(android.app.PendingIntent pendingIntent)
Stops a
PendingIntent scan; you can initiate one by supplying your PendingIntent instance to the
ScanOptions class via ScanOptions.withPendingIntent(PendingIntent) . |
void |
stopScan(ScanFilter filter)
Same as
stopScan() but also unregisters any filter supplied to various overloads of scan() . |
java.lang.String |
toString() |
void |
turnOff()
Disables BLE if manager is
BleManagerState.ON . |
void |
turnOn()
Enables BLE if manager is currently
BleManagerState.OFF or BleManagerState.TURNING_OFF , otherwise does nothing. |
void |
turnOnLocationWithIntent_forOsServices(android.app.Activity callingActivity)
Overload of
turnOnLocationWithIntent_forOsServices(Activity, int) if you don't care about result. |
void |
turnOnLocationWithIntent_forOsServices(android.app.Activity callingActivity,
int requestCode)
If
isLocationEnabledForScanning_byOsServices() returns false , you can use this method to allow the user to enable location services. |
void |
turnOnLocationWithIntent_forPermissions(android.app.Activity callingActivity,
int requestCode)
If
isLocationEnabledForScanning_byOsServices() returns false , you can use this method to allow the user to enable location
through an OS intent. |
void |
turnOnWithIntent(android.app.Activity callingActivity,
int requestCode)
Convenience method to request your user to enable ble in a "standard" way
with an
Intent instead of using turnOn() directly. |
void |
unbondAll()
Removes bonds for all devices that are
BleDeviceState.BONDED . |
boolean |
undiscover(RxBleDevice device)
Forcefully undiscovers a device, disconnecting it first if needed and removing it from this manager's internal list.
|
void |
undiscoverAll()
Undiscovers all devices that are
BleDeviceState.DISCOVERED . |
boolean |
willLocationPermissionSystemDialogBeShown(android.app.Activity callingActivity)
Returns
true if turnOnLocationWithIntent_forPermissions(Activity, int) will pop a system dialog, false if it will bring
you to the OS's Application Settings. |
public static final RxBleDeviceTransformer BLE_DEVICE_TRANSFORMER
BleDevice
instance to an instance of RxBleDevice
via RxJavapublic static final RxBleServerTransformer BLE_SERVER_TRANSFORMER
BleServer
instance to an instance of RxBleServer
via RxJavapublic static RxBleManager createInstance(android.content.Context context, RxBleManagerConfig config, java.lang.String apiKey)
RxBleManager
, if it does not already exist. If it does, that instance is returned here,
and the config and apikey are ignored.public static RxBleManager get(android.content.Context context, RxBleManagerConfig config)
RxBleManager
. This class holds the instance of BleManager
public static RxBleManager get(android.content.Context context)
RxBleManager
. If the instance needs to be created, a default
BleManagerConfig
will be used.public final BleManager getBleManager()
public final <any> scan()
scan(ScanOptions)
, which uses a default instance of ScanOptions
.public final <any> scan(ScanOptions options)
Observable
which kicks off a scan using the provided ScanOptions
once subscribed to. The observable returns an RxDiscoveryEvent
, so
that you can see if the device was DiscoveryListener.LifeCycle.DISCOVERED
, DiscoveryListener.LifeCycle.REDISCOVERED
, or DiscoveryListener.LifeCycle.UNDISCOVERED
. Be aware that the
DiscoveryListener.LifeCycle.REDISCOVERED
state can be emitted many times in a single scan. In most cases, scan_onlyNew(ScanOptions)
will suffice, as it only emits
when a BleDevice
is DiscoveryListener.LifeCycle.DISCOVERED
.
NOTE: This ignores any DiscoveryListener
that is set within the ScanOptions
instance passed into this method.
public final <any> scan_onlyNew(ScanOptions options)
Flowable
which kicks off a scan using the provided ScanOptions
once subscribed to. The observable returns a BleDevice
, as this
method will only ever emit devices that were DiscoveryListener.LifeCycle.DISCOVERED
, as opposed to being DiscoveryListener.LifeCycle.REDISCOVERED
, or DiscoveryListener.LifeCycle.UNDISCOVERED
. If
you care about those other states, then you should use scan(ScanOptions)
instead.
NOTE: This ignores any DiscoveryListener
that is set within the ScanOptions
instance passed into this method.
public <any> observeDiscoveryEvents()
Flowable
which emits RxDiscoveryEvent
whenever a device is DiscoveryListener.LifeCycle.DISCOVERED
, DiscoveryListener.LifeCycle.REDISCOVERED
,
or DiscoveryListener.LifeCycle.UNDISCOVERED
.public <any> observeMgrStateEvents()
public <any> observeDeviceStateEvents()
public <any> observeDeviceConnectEvents()
Flowable
which emits RxDeviceConnectEvent
when any RxBleDevice
gets connected (or fails to).public <any> observeUhOhEvents()
public final <any> observeAssertEvents()
Flowable
which emits RxAssertEvent
when any AssertListener.AssertEvent
s
are posted by the library.public final <any> observeServerStateEvents()
Flowable
which emits RxServerStateEvent
when any ServerStateListener.StateEvent
s
are posted by the library.public final <any> observeBondEvents()
Flowable
which emits RxBondEvent
when any BondListener.BondEvent
s
for all RxBleDevice
s are posted by the library.public final <any> observeReadWriteEvents()
Flowable
which emits RxReadWriteEvent
when any ReadWriteListener.ReadWriteEvent
s
for all RxBleDevice
s are posted by the library.public final <any> observeNotificationEvents()
Flowable
which emits RxNotificationEvent
when any NotificationListener.NotificationEvent
s
for all RxBleDevice
s are posted by the library.public final <any> observeHistoricalDataLoadEvents()
Flowable
which emits RxHistoricalDataLoadEvent
when any HistoricalDataLoadListener.HistoricalDataLoadEvent
s
for all RxBleDevice
s are posted by the library.public final <any> observeOutgoingEvents()
Flowable
which emits RxOutgoingEvent
when any OutgoingListener.OutgoingEvent
s
are posted by the library.public final <any> observeServiceAddEvents()
Flowable
which emits RxServiceAddEvent
when any AddServiceListener.ServiceAddEvent
s
are posted by the library.public final <any> observeAdvertisingEvents()
Flowable
which emits RxAdvertisingEvent
when any AdvertisingListener.AdvertisingEvent
s
are posted by the library.public RxBleDevice getDevice(BleDeviceState state)
BleManager.getDevice(BleDeviceState)
.
Returns an instance of RxBleDevice
.
public RxBleDevice getDevice(java.lang.String macAddress)
BleManager.getDevice(String)
.
Returns an instance of RxBleDevice
.
public final BleDevice getDevice(java.lang.Object... query)
BleManager.getDevice(Object...)
.
Returns an instance of RxBleDevice
.
public final BleDevice getDevice(int mask_BleDeviceState)
BleManager.getDevice(int)
.
Returns an instance of RxBleDevice
.
public final boolean hasDevice(java.lang.String macAddress)
getDevice(String)
returns BleDevice.NULL
.public final boolean hasDevice(BleDevice device)
hasDevice(String)
.public final boolean hasDevice(BleDeviceState state)
public final boolean hasDevice(java.lang.Object... query)
BleDevice.is(Object...)
for the query format.public final boolean hasDevice(int mask_BleDeviceState)
true
if there is any BleDevice
for which BleDevice.isAny(int)
with the given mask returns true
.public <any> getDevices_bonded()
BleManager.getDevices_bonded()
.
Returns an Observable
to cycle through all the devices returned. They will all be instances of RxBleDevice
.
public <any> getDevices()
Observable
that emits all RxBleDevice
s managed by the library.public <any> getDevices_sorted()
Observable
that emits all RxBleDevice
s managed by the library. Devices are emitted in a sorted
order, which is defined by BleManagerConfig.defaultListComparator
.public final <any> getDevices_previouslyConnected()
Observable
which emits the macAddresses of all devices that we know about from both
current and previous app sessions.public RxBleDevice newDevice(java.lang.String macAddress)
BleManager.newDevice(String)
.public RxBleDevice newDevice(java.lang.String macAddress, java.lang.String name)
BleManager.newDevice(String, String)
.public RxBleDevice newDevice(java.lang.String macAddress, BleManagerConfig config)
BleManager.newDevice(String, BleDeviceConfig)
.public RxBleDevice newDevice(java.lang.String macAddress, java.lang.String name, BleDeviceConfig config)
BleManager.newDevice(String, String, BleDeviceConfig)
.public final int getDeviceCount()
BleDeviceState.DISCOVERED
.public final int getDeviceCount(BleDeviceState state)
public final int getDeviceCount(java.lang.Object... query)
BleDevice.is(Object...)
for the query format.public final boolean hasDevices()
scan(ScanOptions)
or newDevice(String)
(or overloads) then this will return false.public final void removeDeviceFromCache(RxBleDevice device)
RxBleDevice
from SweetBlue's internal device cache list. You should never have to call this
yourself (and probably shouldn't), but it's here for flexibility.public final void removeAllDevicesFromCache()
RxBleDevice
s from SweetBlue's internal device cache list. You should never have to call this
yourself (and probably shouldn't), but it's here for flexibility.public final HistoricalData newHistoricalData(byte[] data, EpochTime epochTime)
HistoricalData
instance using
BleNodeConfig.historicalDataFactory
if available.public final HistoricalData newHistoricalData(byte[] data, EpochTime epochTime, java.lang.String macAddress)
newHistoricalData(byte[], EpochTime)
but tries to use
BleNode.newHistoricalData(byte[], EpochTime)
if we have a device
matching the given mac address.public final RxBleServer getServer(IncomingListener listener, GattDatabase db, AddServiceListener addListener)
BleManager.getServer(IncomingListener, GattDatabase, AddServiceListener)
.
NOTE: The device creation is performed on the thread which SweetBlue is using, and this method is blocking.
public final RxBleServer getServer()
getServer(IncomingListener, GattDatabase, AddServiceListener)
, which passes null for all arguments.public final boolean undiscover(RxBleDevice device)
GenericListener_Void.onEvent(Event)
with DiscoveryListener.LifeCycle.UNDISCOVERED
will be called.
No clear use case has been thought of but the method is here just in case anyway.true
if the device was undiscovered, false
if device is already BleDeviceState.UNDISCOVERED
or manager
doesn't contain an instance, checked referentially, not through RxBleDevice.equals(RxBleDevice)
(i.e. by mac address).public final void clearQueue()
public final void clearSharedPreferences(RxBleDevice device)
clearSharedPreferences(String)
.clearSharedPreferences(String)
public final void clearSharedPreferences(java.lang.String macAddress)
SharedPreferences
for a particular device.public final void clearSharedPreferences()
SharedPreferences
for all devices.public final boolean isForegrounded()
public final java.lang.String toString()
toString
in class java.lang.Object
public final void shutdown()
BleManager
, and RxBleManager
static instances. This is meant to be called upon application exit. However, to use it again,
just call BleManager.get(Context)
, or BleManager.get(Context, BleManagerConfig)
again.public final void setConfig(RxBleManagerConfig config)
public final RxBleManagerConfig getConfigClone()
public final boolean isAny(BleManagerState... states)
public final boolean isAll(BleManagerState... states)
isAny(BleManagerState...)
public final boolean is(BleManagerState state)
isAny(BleManagerState...)
public final boolean isAny(int mask_BleManagerState)
true
if there is partial bitwise overlap between the provided value and getStateMask()
.isAll(int)
public final boolean isAll(int mask_BleManagerState)
true
if there is complete bitwise overlap between the provided value and getStateMask()
.isAny(int)
public final Interval getTimeInState(BleManagerState state)
RxBleDevice.getTimeInState(BleDeviceState)
.public final boolean isBleSupported()
public final boolean isAdvertisingSupportedByAndroidVersion()
public final boolean isAdvertisingSupportedByChipset()
public final boolean isAdvertisingSupported()
public final boolean isBluetooth5SupportedByAndroidVersion()
true
if the android device is running an android OS version which supports Bluetooth 5 features.public final boolean isBluetooth5LongRangeSupported()
true
if the android device supports the bluetooth 5 feature of long range (up to 4x the range of Bluetooth 4.x).
It's possible for this to return true
, and isBluetooth5HighSpeedSupported()
to return false
.
public final boolean isBluetooth5HighSpeedSupported()
true
if the android device supports the high speed feature of Bluetooth 5 (2x the speed of Bluetooth 4.x).public final boolean isBluetooth5Supported()
isBluetooth5SupportedByAndroidVersion()
,
isBluetooth5HighSpeedSupported()
and isBluetooth5LongRangeSupported()
.public final void turnOff()
BleManagerState.ON
. This disconnects all current
connections, stops scanning, and forgets all discovered devices.public final android.bluetooth.BluetoothManager getNative()
public final android.bluetooth.BluetoothAdapter getNativeAdapter()
public final void pushWakeLock()
Manifest.permission.WAKE_LOCK
permission. Gives you access to the internal
wake lock as a convenience and eventually calls PowerManager.WakeLock.acquire()
.BleManagerConfig.manageCpuWakeLock
public final void popWakeLock()
pushWakeLock()
, eventually calls PowerManager.WakeLock.release()
.public final boolean ASSERT(boolean condition)
AssertListener
if condition is false. Will post a Log.ERROR
-level
message with a stack trace to the console as well if BleManagerConfig.loggingOptions
is not LogOptions.OFF
.public final boolean ASSERT(boolean condition, java.lang.String message)
ASSERT(boolean)
but with an added message.public final int getStateMask()
BleManagerState
for the manager instance.BleManagerState
public final void turnOn()
BleManagerState.OFF
or BleManagerState.TURNING_OFF
, otherwise does nothing.
For a convenient way to ask your user first see turnOnWithIntent(android.app.Activity, int)
.public final void reset()
turnOff()
then turnOn()
,
but also does other things like removing all bonds (similar to unbondAll()
) and
other "special sauce" such that you should use this method instead of trying to reset the
stack manually with component calls.
BleManagerState.RESETTING
public final void reset(ResetListener listener)
reset()
but with a convenience callback for when the reset is
completed and the native BLE stack is (should be) back to normal.BleManagerState.RESETTING
public final void nukeBle()
BleManager.reset()
, only this also calls the factoryReset method hidden in BluetoothAdapter
after turning
off BLE, and running the crash resolver. It's not clear what this method does, hence why this is marked as being experimental.reset()
public final void nukeBle(ResetListener resetListener)
BleManager.reset(ResetListener)
, only this also calls the factoryReset method hidden in BluetoothAdapter
after turning
off BLE, and running the crash resolver. It's not clear what this method does, hence why this is marked as being experimental.reset(ResetListener)
public final void unbondAll()
BleDeviceState.BONDED
.
Essentially a convenience method for calling RxBleDevice.unbond()
,
on each device individually.public final void disconnectAll()
BleDeviceState.BLE_CONNECTED
.
Essentially a convenience method for calling RxBleDevice.disconnect()
,
on each device individually.public final void disconnectAll_remote()
disconnectAll()
but drills down to RxBleDevice.disconnect_remote()
instead.public final void undiscoverAll()
BleDeviceState.DISCOVERED
.
Essentially a convenience method for calling RxBleDevice.undiscover()
,
on each device individually.public final void turnOnLocationWithIntent_forOsServices(android.app.Activity callingActivity, int requestCode)
isLocationEnabledForScanning_byOsServices()
returns false
, you can use this method to allow the user to enable location services.
isLocationEnabledForScanning_byOsServices()
returns false
but all other overloads of isLocationEnabledForScanning()
return true
then
SweetBlue will fall back to classic discovery through BluetoothAdapter.startDiscovery()
when you call scan(ScanOptions)
, so you may not have to use this.public final void turnOnLocationWithIntent_forOsServices(android.app.Activity callingActivity)
turnOnLocationWithIntent_forOsServices(Activity, int)
if you don't care about result.BluetoothEnabler
public final boolean willLocationPermissionSystemDialogBeShown(android.app.Activity callingActivity)
true
if turnOnLocationWithIntent_forPermissions(Activity, int)
will pop a system dialog, false
if it will bring
you to the OS's Application Settings. The true
case happens if the app has never shown a request Location Permissions dialog or has shown a request Location Permission dialog and the user has yet to select "Never ask again". This method is used to weed out the false
negative from Activity.shouldShowRequestPermissionRationale(String)
when the Location Permission has never been requested. Make sure to use this in conjunction with isLocationEnabledForScanning_byRuntimePermissions()
which will tell you if permissions are already enabled.BluetoothEnabler
public final void turnOnLocationWithIntent_forPermissions(android.app.Activity callingActivity, int requestCode)
isLocationEnabledForScanning_byOsServices()
returns false
, you can use this method to allow the user to enable location
through an OS intent. The result of the request (i.e. what the user chose) is passed back through Activity.onRequestPermissionsResult(int, String[], int[])
with the requestCode provided as the second parameter to this method. If the user selected "Never ask again" the function will open up the app settings screen where the
user can navigate to enable the permissions.public final boolean isScanningReady()
scan(ScanOptions)
, will succeed or not. Basically a convenience for checking if both
isLocationEnabledForScanning()
and is(BleManagerState)
with BleManagerState.SCANNING
return true
.public final boolean isScanning()
true
if the BleManager
is in any of the following states: BleManagerState.SCANNING
, BleManagerState.SCANNING_PAUSED
, BleManagerState.BOOST_SCANNING
, or BleManagerState.STARTING_SCAN
public final boolean isLocationEnabledForScanning()
true
if location is enabled to a degree that allows scanning on Build.VERSION_CODES.M
and above.
If this returns false
it means you're on Android M and you either (A) do not have Manifest.permission.ACCESS_COARSE_LOCATION
(or Manifest.permission.ACCESS_FINE_LOCATION
in your AndroidManifest.xml, see isLocationEnabledForScanning_byManifestPermissions()
), or (B)
runtime permissions for aformentioned location permissions are off (see isLocationEnabledForScanning_byRuntimePermissions()
and
https://developer.android.com/training/permissions/index.html), or (C) location services on the phone are disabled (see isLocationEnabledForScanning_byOsServices()
).
true
then you are good to go for calling scan(ScanOptions)
.public final boolean isLocationEnabledForScanning_byManifestPermissions()
true
if you're either pre-Android-M, or app has permission for either Manifest.permission.ACCESS_COARSE_LOCATION
or Manifest.permission.ACCESS_FINE_LOCATION
in your AndroidManifest.xml, false
otherwise.scan(ScanOptions)
,
BluetoothEnabler
public final boolean isLocationEnabledForScanning_byRuntimePermissions()
true
if you're either pre-Android-M, or app has runtime permissions enabled by checking
ContextCompat.checkSelfPermission(android.content.Context, java.lang.String)
See more information at https://developer.android.com/training/permissions/index.html.public final boolean isLocationEnabledForScanning_byOsServices()
true
if you're either pre-Android-M, or location services are enabled, the same is if you go to the Android Settings app
and manually toggle Location ON/OFF.
false
but all other overloads of isLocationEnabledForScanning()
return true
then
SweetBlue will fall back to classic discovery through BluetoothAdapter.startDiscovery()
when you call scan(ScanOptions)
.public final void turnOnWithIntent(android.app.Activity callingActivity, int requestCode)
Intent
instead of using turnOn()
directly.
Result will be posted as normal to Activity.onActivityResult(int, int, Intent)
.
If current state is BleManagerState.ON
or BleManagerState.TURNING_ON
this method early outs and does nothing.BluetoothEnabler
public final void onResume()
public final void onPause()
Activity.onPause()
for each Activity
in your application. This doesn't do much for now, just a little bookkeeping and stops scan automatically if
BleManagerConfig.stopScanOnPause
is true
. Strictly speaking you don't *have* to call this method,
but another good reason is for future-proofing. Later releases of this library may do other more important things
in this method so it's good to have it being called just in case.public final android.content.Context getApplicationContext()
Application
provided to the constructor.@Deprecated public final void stopAllScanning()
stopScan()
or stopScan(ScanFilter)
instead.
This method will be removed in v3.1.
Convenience that will call both BleManager.stopPeriodicScan()
and BleManager.stopScan()
for you. This is here as a stop-gap
in the off chance the scan doesn't stop when you dispose the Flowable
returned from scan(ScanOptions)
.public final void stopScan()
public final void stopScan(ScanFilter filter)
stopScan()
but also unregisters any filter supplied to various overloads of scan()
.
Calling stopScan()
alone will keep any previously registered filters active.public final void stopScan(android.app.PendingIntent pendingIntent)
PendingIntent
scan; you can initiate one by supplying your PendingIntent instance to the
ScanOptions
class via ScanOptions.withPendingIntent(PendingIntent)
.
NOTE: You may still receive some callbacks after calling this method, as it seems the android stack batches
these results, and calls them in order.