public final class BleManager
extends java.lang.Object
get(android.content.Context, BleManagerConfig)
or its overloads. Make sure
to hook up this manager to lifecycle events for your app as a whole: onPause()
and onResume()
.
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
Manifest.permission.WAKE_LOCK
is recommended but optional, needed if BleManagerConfig.manageCpuWakeLock
is enabled to aid with reconnect loops.
As of now it's enabled by default.
Manifest.permission.ACCESS_COARSE_LOCATION
(or Manifest.permission.ACCESS_FINE_LOCATION
)
is also strongly recommended but optional. Without it, startScan()
and overloads will not properly return results in Build.VERSION_CODES.M
and above.
See startScan(Interval, ScanFilter, DiscoveryListener)
for more information.
public class MyActivity extends Activity
{
@Override protected void onCreate(Bundle savedInstanceState)
{
// A ScanFilter decides whether a BleDevice instance will be created
// and passed to the DiscoveryListener implementation below.
final ScanFilter scanFilter = new ScanFilter()
{
@Override public Please onEvent(ScanEvent e)
{
return Please.acknowledgeIf(e.name_normalized().contains("my_device"))
.thenStopScan();
}
};
// New BleDevice instances are provided through this listener.
// Nested listeners then listen for connection and read results.
final DiscoveryListener discoveryListener = new DiscoveryListener()
{
@Override public void onEvent(DiscoveryEvent e)
{
if( e.was(LifeCycle.DISCOVERED) )
{
e.device().connect(new StateListener()
{
@Override public void onEvent(StateEvent e)
{
if( e.didEnter(BleDeviceState.INITIALIZED) )
{
e.device().read(Uuids.BATTERY_LEVEL, new ReadWriteListener()
{
@Override public void onEvent(ReadWriteEvent e)
{
if( e.wasSuccess() )
{
Log.i("", "Battery level is " + e.data_byte() + "%");
}
}
});
}
}
});
}
}
};
// Helps you navigate the treacherous waters of Android M Location requirements for scanning.
BluetoothEnabler.start(this, new DefaultBluetoothEnablerFilter()
{
@Override public Please onEvent(BluetoothEnablerEvent e)
{
if( e.isDone() )
{
e.bleManager().startScan(scanFilter, discoveryListener);
}
return super.onEvent(e);
}
});
}
Modifier and Type | Field and Description |
---|---|
java.lang.Object |
appData
Field for app to associate any data it wants with the singleton instance of this class
instead of having to subclass or manage associative hash maps or something.
|
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(BleDevice 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 BleManager |
createInstance(android.content.Context context,
BleManagerConfig config,
java.lang.String apiKey)
Use this method to create the
BleManager singleton instance. |
static BleManager |
createInstance(android.content.Context context,
java.lang.String apiKey)
Overload of
createInstance(Context, BleManagerConfig, String) , which uses the default config options. |
void |
disconnectAll_remote()
Same as
disconnectAll() but drills down to BleDevice.disconnect_remote() instead. |
void |
disconnectAll()
Disconnects all devices that are
BleDeviceState.BLE_CONNECTED . |
static BleManager |
get(android.content.Context context)
Create the singleton instance or retrieve the already-created singleton instance with default configuration options set.
|
static BleManager |
get(android.content.Context context,
BleManagerConfig config)
Create the singleton instance or retrieve the already-created singleton instance with custom configuration options set.
|
android.content.Context |
getApplicationContext()
Returns the
Application provided to the constructor. |
BleManagerConfig |
getConfigClone() |
BleDevice |
getDevice(BleDeviceState state)
Returns the first device that is in the given state, or
BleDevice.NULL if no match is found. |
BleDevice |
getDevice(int mask_BleDeviceState)
Returns the first device which returns
true for BleDevice.isAny(int) , or BleDevice.NULL if no such device is found. |
BleDevice |
getDevice(java.lang.Object... query)
Returns the first device that matches the query, or
BleDevice.NULL if no match is found. |
BleDevice |
getDevice(java.lang.String macAddress)
Gets a known
BleDeviceState.DISCOVERED device by MAC address, or BleDevice.NULL if there is no such device. |
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.
|
java.util.Set<BleDevice> |
getDevices_bonded()
Convenience method to return a
Set of currently bonded devices. |
java.util.List<BleDevice> |
getDevices_List_sorted()
Same as
getDevices_List() , but sorts the list using BleManagerConfig.defaultListComparator . |
java.util.List<BleDevice> |
getDevices_List_sorted(BleDeviceState state)
Same as
getDevices_List(BleDeviceState) except the list is sorted using BleManagerConfig.defaultListComparator . |
java.util.List<BleDevice> |
getDevices_List_sorted(int mask_BleDeviceState)
Same as
getDevices_List(int) except the list is sorted using BleManagerConfig.defaultListComparator . |
java.util.List<BleDevice> |
getDevices_List_sorted(java.lang.Object... query)
Same as
getDevices_List(Object...) except the list is sorted using BleManagerConfig.defaultListComparator . |
java.util.List<BleDevice> |
getDevices_List()
Overload of
getDevices() that returns a List for you. |
java.util.List<BleDevice> |
getDevices_List(BleDeviceState state)
Overload of
getDevices(BleDeviceState) that returns a List for you. |
java.util.List<BleDevice> |
getDevices_List(int mask_BleDeviceState)
Overload of
getDevices(int) that returns a List for you. |
java.util.List<BleDevice> |
getDevices_List(java.lang.Object... query)
Overload of
getDevices(Object...) that returns a List for you. |
java.util.Iterator<java.lang.String> |
getDevices_previouslyConnected()
Returns the mac addresses of all devices that we know about from both current and previous
app sessions.
|
BleDeviceIterator |
getDevices_sorted()
Same as
getDevices() , but with the devices sorted using BleManagerConfig.defaultListComparator , which
by default sorts by BleDevice.getName_debug() . |
BleDeviceIterator |
getDevices()
Returns all the devices managed by this class.
|
BleDeviceIterator |
getDevices(BleDeviceState state)
Same as
getDevice(BleDeviceState) except returns all matching devices. |
void |
getDevices(ForEach_Breakable<BleDevice> forEach)
Overload of
getDevices(ForEach_Void)
if you need to break out of the iteration at any point. |
void |
getDevices(ForEach_Breakable<BleDevice> forEach,
BleDeviceState state)
Overload of
getDevices(ForEach_Void, BleDeviceState)
if you need to break out of the iteration at any point. |
void |
getDevices(ForEach_Void<BleDevice> forEach)
Offers a more "functional" means of iterating through the internal list of devices instead of
using
getDevices() or getDevices_List() . |
void |
getDevices(ForEach_Void<BleDevice> forEach,
BleDeviceState state)
Same as
getDevices(ForEach_Void) but will only return devices
in the given state provided. |
BleDeviceIterator |
getDevices(int mask_BleDeviceState)
Same as
getDevices() except filters using BleDevice.isAny(int) . |
java.util.List<BleDevice> |
getDevices(android.content.Intent intentFromScan)
This is a convenience method to get an
ArrayList of BleDevice s from the Intent
which was delivered as a result of calling startScan(ScanOptions) when using a
PendingIntent . |
BleDeviceIterator |
getDevices(java.lang.Object... query)
Same as
getDevice(Object...) except returns all matching devices. |
DiscoveryListener |
getListener_Discovery()
Returns the discovery listener set with
setListener_Discovery(DiscoveryListener) or
BleManagerConfig.defaultDiscoveryListener , or null if not set. |
android.bluetooth.BluetoothManager |
getNative()
Returns the native manager.
|
android.bluetooth.BluetoothAdapter |
getNativeAdapter()
Returns the native bluetooth adapter.
|
BleServer |
getServer()
Overload of
getServer(IncomingListener) without any initial set-up parameters. |
BleServer |
getServer(GattDatabase gattDatabase)
Overload of
getServer(GattDatabase, AddServiceListener) , with no AddServiceListener set. |
BleServer |
getServer(GattDatabase gattDatabase,
AddServiceListener addServiceListener)
Overload of
getServer(IncomingListener, GattDatabase, AddServiceListener) , with no IncomingListener set. |
BleServer |
getServer(IncomingListener incomingListener)
Returns a
BleServer instance. |
BleServer |
getServer(IncomingListener incomingListener,
GattDatabase gattDatabase,
AddServiceListener addServiceListener)
Returns a
BleServer instance. |
int |
getStateMask()
Returns the abstracted bitwise state mask representation of
BleManagerState for the manager instance. |
Interval |
getTimeInState(BleManagerState state)
See similar comment for
BleDevice.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
*
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
startScan() (or overloads), will succeed or not. |
BleDevice |
newDevice(android.bluetooth.BluetoothDevice nativeDevice)
Similar to
newDevice(String) , but this method accepts a native BluetoothDevice as an argument. |
BleDevice |
newDevice(android.bluetooth.BluetoothDevice nativeDevice,
BleDeviceConfig config)
Same as
newDevice(BluetoothDevice) , but allows passing in a BleDeviceConfig as well. |
BleDevice |
newDevice(java.lang.String macAddress)
Same as
newDevice(String, String, BleDeviceConfig) but uses an empty string for the name
and passes a null BleDeviceConfig , which results in inherited options from BleManagerConfig . |
BleDevice |
newDevice(java.lang.String macAddress,
BleDeviceConfig config)
Same as
newDevice(String) but passes a BleDeviceConfig to be used as well. |
BleDevice |
newDevice(java.lang.String macAddress,
java.lang.String name)
Same as
newDevice(String) but allows a custom name also. |
BleDevice |
newDevice(java.lang.String macAddress,
java.lang.String name,
BleDeviceConfig config)
Overload of
newDevice(String, String, byte[], BleDeviceConfig) . |
BleDevice |
newDevice(java.lang.String macAddress,
java.lang.String name,
byte[] scanRecord,
BleDeviceConfig config)
Creates a new
BleDevice or returns an existing one if the macAddress matches. |
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
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
reset(ResetListener) , only this also calls the factoryReset method hidden in BluetoothAdapter after turning
off BLE, and running the crash resolver. |
void |
onPause()
This method is automatically called for you, if
BleManagerConfig.autoPauseResumeDetection is set to true , which is the default. |
void |
onResume()
This method is automatically called for you, if
BleManagerConfig.autoPauseResumeDetection is set to true , which is the default. |
void |
popWakeLock()
Opposite of
pushWakeLock() , eventually calls PowerManager.WakeLock.release() . |
void |
pushWakeLock()
Requires the
Manifest.permission.WAKE_LOCK permission. |
void |
removeAllDevicesFromCache()
Removes all
BleDevice s from SweetBlue's internal device cache list. |
void |
removeDeviceFromCache(BleDevice device)
Removes the given
BleDevice 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. |
void |
setConfig(BleManagerConfig config_nullable)
Updates the config options for this instance after calling
get(android.content.Context) or get(android.content.Context, BleManagerConfig) . |
void |
setListener_Advertising(AdvertisingListener listener)
Set a listener here to be notified of the result of starting to advertise.
|
void |
setListener_Assert(AssertListener listener_nullable)
Set a listener here to be notified whenever
ASSERT(boolean) fails. |
void |
setListener_Bond(BondListener listener_nullable)
Convenience method to set a default back up listener for all
BondListener.BondEvent s across all BleDevice instances. |
void |
setListener_DeviceConnect(DeviceConnectListener listener_nullable)
Convenience method to handle
BleDevice connect events at a manager level. |
void |
setListener_DeviceReconnect(DeviceReconnectFilter listener_nullable)
Convenience method to handle connection fail events at the manager level.
|
void |
setListener_DeviceState(DeviceStateListener listener_nullable)
Convenience method to listen for all changes in
BleDeviceState for all devices. |
void |
setListener_Discovery(DiscoveryListener listener_nullable)
Set a listener here to be notified whenever a
BleDevice is discovered, rediscovered, or undiscovered. |
void |
setListener_HistoricalDataLoad(HistoricalDataLoadListener listener_nullable)
Sets a default backup
HistoricalDataLoadListener that will be invoked
for all historical data loads to memory for all uuids for all devices. |
void |
setListener_Incoming(IncomingListener listener_nullable)
Convenience method to handle server request events at the manager level.
|
void |
setListener_Notification(NotificationListener listener_nullable) |
void |
setListener_Outgoing(OutgoingListener listener_nullable)
Convenience method to listen for completion of all outgoing messages from
BleServer instances. |
void |
setListener_Read_Write(ReadWriteListener listener_nullable)
Sets a default backup
ReadWriteListener that will be called for all BleDevice instances. |
void |
setListener_ServerReconnectFilter(ServerReconnectFilter listener_nullable)
Convenience method to handle server connection fail events at the manager level.
|
void |
setListener_ServerState(ServerStateListener listener_nullable)
Convenience method to listen for all changes in
BleServerState for all servers. |
void |
setListener_ServiceAdd(AddServiceListener listener_nullable)
Convenience method to listen for all service addition events for all servers.
|
void |
setListener_State(ManagerStateListener listener_nullable)
Set a listener here to be notified whenever this manager's
BleManagerState changes. |
void |
setListener_UhOh(UhOhListener listener_nullable)
Set a listener here to be notified whenever we encounter an
UhOhListener.UhOh . |
void |
shutdown()
Disconnects all devices, shuts down the BleManager, and it's backing thread, and unregisters any receivers that may be in use.
|
void |
startPeriodicScan(Interval scanActiveTime,
Interval scanPauseTime)
Deprecated.
use
startScan(ScanOptions) instead.
This method will be removed in v3.1.
Manually starts a periodic scan. |
void |
startPeriodicScan(Interval scanActiveTime,
Interval scanPauseTime,
DiscoveryListener discoveryListener)
Deprecated.
use
startScan(ScanOptions) instead.
This method will be removed in v3.1.
Same as startPeriodicScan(Interval, Interval) but calls setListener_Discovery(DiscoveryListener) for you too. |
void |
startPeriodicScan(Interval scanActiveTime,
Interval scanPauseTime,
ScanFilter filter)
Deprecated.
use
startScan(ScanOptions) instead.
This method will be removed in v3.1.
Same as startPeriodicScan(Interval, Interval) but adds a filter too. |
void |
startPeriodicScan(Interval scanActiveTime,
Interval scanPauseTime,
ScanFilter filter,
DiscoveryListener discoveryListener)
Deprecated.
use
startScan(ScanOptions) instead.
This method will be removed in v3.1.
Same as startPeriodicScan(Interval, Interval) but calls setListener_Discovery(DiscoveryListener) for you too and adds a filter. |
void |
startPeriodicScan(Interval scanActiveTime,
Interval scanPauseTime,
ScanFilter filter,
ScanFilter.ApplyMode filterApplyMode,
DiscoveryListener discoveryListener)
Deprecated.
use
startScan(ScanOptions) instead.
This method will be removed in v3.1.
Same as startPeriodicScan(Interval, Interval) but calls setListener_Discovery(DiscoveryListener) for you too and adds a filter and a filter mode. |
boolean |
startScan()
Starts a scan that will continue indefinitely until
stopScan() is called. |
boolean |
startScan(DiscoveryListener discoveryListener)
Same as
startScan() but also calls setListener_Discovery(DiscoveryListener) for you. |
boolean |
startScan(Interval scanTime)
Starts a scan that will generally last for the given time (roughly).
|
boolean |
startScan(Interval scanTime,
DiscoveryListener discoveryListener)
|
boolean |
startScan(Interval scanTime,
ScanFilter filter)
|
boolean |
startScan(Interval scanTime,
ScanFilter filter,
DiscoveryListener discoveryListener)
Same as
startScan(Interval) but sets an ephemeral setListener_Discovery(DiscoveryListener) that you provide. |
boolean |
startScan(ScanFilter filter)
Calls
startScan(Interval, ScanFilter) with Interval.INFINITE . |
boolean |
startScan(ScanFilter filter,
DiscoveryListener discoveryListener)
Same as
startScan() but also calls setListener_Discovery(DiscoveryListener) for you. |
boolean |
startScan(ScanOptions options) |
void |
stopAllScanning()
Deprecated.
use
stopScan() or stopScan(ScanFilter) instead.
This method will be removed in v3.1.
Convenience that will call both stopPeriodicScan() and stopScan() for you. |
void |
stopPeriodicScan()
Deprecated.
use
stopScan() or stopScan(ScanFilter) instead.
This method will be removed in v3.1.
Stops a periodic scan previously started explicitly with startPeriodicScan(Interval, Interval) . |
void |
stopPeriodicScan(ScanFilter filter)
Deprecated.
use
stopScan() or stopScan(ScanFilter) instead.
This method will be removed in v3.1.
Same as stopPeriodicScan() but will also unregister any ScanFilter provided
through startPeriodicScan(Interval, Interval, ScanFilter) or other overloads. |
void |
stopScan()
Stops any scans previously started by
startScan() . |
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 startScan() . |
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(BleDevice 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 java.lang.Object appData
BleNode.appData
,
BleNode.appData
public static BleManager get(android.content.Context context)
get(android.content.Context, BleManagerConfig)
(for example in another
Activity
), the BleManagerConfig
originally passed in will be used.
Otherwise, if a new instance is to be created, this calls get(android.content.Context, BleManagerConfig)
with a BleManagerConfig
instance created using the default constructor BleManagerConfig.BleManagerConfig()
.
You must put your API key into a file called sweetblue_api_key.txt
, which resides in the assets folder.createInstance(Context, String)
public static BleManager get(android.content.Context context, BleManagerConfig config)
Activity
with different BleManagerConfig
options set then the newer options overwrite the older options.
You must put your API key into a file called sweetblue_api_key.txt
, which resides in the assets folder.public static BleManager createInstance(android.content.Context context, java.lang.String apiKey)
createInstance(Context, BleManagerConfig, String)
, which uses the default config options. You can always set a new
BleManagerConfig
by calling setConfig(BleManagerConfig)
on the created instance.public static BleManager createInstance(android.content.Context context, BleManagerConfig config, java.lang.String apiKey)
BleManager
singleton instance. You would only need to use this method if you want to pass in
your SweetBlue API key via code (rather than putting the api key into a file in the assets folder).public final void setConfig(BleManagerConfig config_nullable)
get(android.content.Context)
or get(android.content.Context, BleManagerConfig)
.
Providing a null
value will set everything back to default values.public final BleManagerConfig 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)
BleDevice.getTimeInState(BleDeviceState)
.BleDevice.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 setListener_HistoricalDataLoad(HistoricalDataLoadListener listener_nullable)
HistoricalDataLoadListener
that will be invoked
for all historical data loads to memory for all uuids for all devices.public final void setListener_UhOh(UhOhListener listener_nullable)
UhOhListener.UhOh
.public final void setListener_Assert(AssertListener listener_nullable)
ASSERT(boolean)
fails.
Mostly for use by internal library developers.public final void setListener_Discovery(DiscoveryListener listener_nullable)
BleDevice
is discovered, rediscovered, or undiscovered.public final DiscoveryListener getListener_Discovery()
setListener_Discovery(DiscoveryListener)
or
BleManagerConfig.defaultDiscoveryListener
, or null
if not set.public final void setListener_State(ManagerStateListener listener_nullable)
BleManagerState
changes.public final void setListener_DeviceState(DeviceStateListener listener_nullable)
BleDeviceState
for all devices.
The listener provided will get called in addition to and after the listener, if any, provided
to BleDevice.setListener_State(DeviceStateListener)
.public final void setListener_ServerReconnectFilter(ServerReconnectFilter listener_nullable)
BleServer.setListener_ReconnectFilter(ServerReconnectFilter)
. This is unlike the behavior
behind (for example) setListener_ServerState(ServerStateListener)
because
ReconnectFilter.onConnectFailed(ReconnectFilter.ConnectFailEvent)
requires a return value.public final void setListener_Incoming(IncomingListener listener_nullable)
BleServer.setListener_Incoming(IncomingListener)
. This is unlike the behavior (for example)
behind setListener_Outgoing(OutgoingListener)
because
IncomingListener.onEvent(IncomingListener.IncomingEvent)
requires a return value.public final void setListener_ServiceAdd(AddServiceListener listener_nullable)
BleServer.setListener_ServiceAdd(AddServiceListener)
.public final void setListener_ServerState(ServerStateListener listener_nullable)
BleServerState
for all servers.
The listener provided will get called in addition to and after the listener, if any, provided
to BleServer.setListener_State(ServerStateListener)
.public final void setListener_Outgoing(OutgoingListener listener_nullable)
BleServer
instances. The listener provided will get called in addition to and after the listener, if any, provided
to BleServer.setListener_Outgoing(OutgoingListener)
.public final void setListener_DeviceReconnect(DeviceReconnectFilter listener_nullable)
BleDevice.setListener_Reconnect(DeviceReconnectFilter)
, the return value of that one will be used
internally by SweetBlue for that BleDevice
(but the event will still be pumped to the listener provided here).public final void setListener_DeviceConnect(DeviceConnectListener listener_nullable)
BleDevice
connect events at a manager level. This listener simply reports when
a device is connected, or has failed to connect -- GenericListener_Void.onEvent(Event)
may fire multiple times
when DeviceConnectListener.ConnectEvent.wasSuccess()
is false
, as SweetBlue may be retrying the connection
in the background, remember to check DeviceConnectListener.ConnectEvent.isRetrying()
.public final void setListener_Bond(BondListener listener_nullable)
BondListener.BondEvent
s across all BleDevice
instances.public final void setListener_Read_Write(ReadWriteListener listener_nullable)
ReadWriteListener
that will be called for all BleDevice
instances.
public final void setListener_Notification(NotificationListener listener_nullable)
public final void setListener_Advertising(AdvertisingListener listener)
@Deprecated public final void startPeriodicScan(Interval scanActiveTime, Interval scanPauseTime)
startScan(ScanOptions)
instead.
This method will be removed in v3.1.
Manually starts a periodic scan.BluetoothEnabler
@Deprecated public final void startPeriodicScan(Interval scanActiveTime, Interval scanPauseTime, DiscoveryListener discoveryListener)
startScan(ScanOptions)
instead.
This method will be removed in v3.1.
Same as startPeriodicScan(Interval, Interval)
but calls setListener_Discovery(DiscoveryListener)
for you too.BluetoothEnabler
@Deprecated public final void startPeriodicScan(Interval scanActiveTime, Interval scanPauseTime, ScanFilter filter)
startScan(ScanOptions)
instead.
This method will be removed in v3.1.
Same as startPeriodicScan(Interval, Interval)
but adds a filter too.BluetoothEnabler
@Deprecated public final void startPeriodicScan(Interval scanActiveTime, Interval scanPauseTime, ScanFilter filter, DiscoveryListener discoveryListener)
startScan(ScanOptions)
instead.
This method will be removed in v3.1.
Same as startPeriodicScan(Interval, Interval)
but calls setListener_Discovery(DiscoveryListener)
for you too and adds a filter.BluetoothEnabler
@Deprecated public final void startPeriodicScan(Interval scanActiveTime, Interval scanPauseTime, ScanFilter filter, ScanFilter.ApplyMode filterApplyMode, DiscoveryListener discoveryListener)
startScan(ScanOptions)
instead.
This method will be removed in v3.1.
Same as startPeriodicScan(Interval, Interval)
but calls setListener_Discovery(DiscoveryListener)
for you too and adds a filter and a filter mode.BluetoothEnabler
@Deprecated public final void stopPeriodicScan(ScanFilter filter)
stopScan()
or stopScan(ScanFilter)
instead.
This method will be removed in v3.1.
Same as stopPeriodicScan()
but will also unregister any ScanFilter
provided
through startPeriodicScan(Interval, Interval, ScanFilter)
or other overloads.@Deprecated public final void stopPeriodicScan()
stopScan()
or stopScan(ScanFilter)
instead.
This method will be removed in v3.1.
Stops a periodic scan previously started explicitly with startPeriodicScan(Interval, Interval)
.public final boolean startScan()
stopScan()
is called.true
if scan started, false>
otherwise - usually this means this manager is not BleManagerState.ON
.BluetoothEnabler
public final boolean startScan(ScanFilter filter)
startScan(Interval, ScanFilter)
with Interval.INFINITE
.true
if scan started, false>
otherwise - usually this means this manager is not BleManagerState.ON
.BluetoothEnabler
public final boolean startScan(DiscoveryListener discoveryListener)
startScan()
but also calls setListener_Discovery(DiscoveryListener)
for you.true
if scan started, false>
otherwise - usually this means this manager is not BleManagerState.ON
.BluetoothEnabler
public final boolean startScan(Interval scanTime, ScanFilter filter)
true
if scan started, false>
otherwise - usually this means this manager is not BleManagerState.ON
.BluetoothEnabler
public final boolean startScan(Interval scanTime, DiscoveryListener discoveryListener)
true
if scan started, false>
otherwise - usually this means this manager is not BleManagerState.ON
.BluetoothEnabler
public final boolean startScan(ScanFilter filter, DiscoveryListener discoveryListener)
startScan()
but also calls setListener_Discovery(DiscoveryListener)
for you.true
if scan started, false>
otherwise - usually this means this manager is not BleManagerState.ON
.BluetoothEnabler
public final boolean startScan(Interval scanTime)
true
if scan started, false>
otherwise - usually this means this manager is not BleManagerState.ON
.BluetoothEnabler
public final boolean startScan(Interval scanTime, ScanFilter filter, DiscoveryListener discoveryListener)
startScan(Interval)
but sets an ephemeral setListener_Discovery(DiscoveryListener)
that you provide.
Build.VERSION_CODES.M
and up, in order for this method to return scan events
through ScanFilter
you must have Manifest.permission.ACCESS_COARSE_LOCATION
or Manifest.permission.ACCESS_FINE_LOCATION
in your AndroidManifest.xml, AND enabled at runtime (see isLocationEnabledForScanning_byRuntimePermissions()
and turnOnLocationWithIntent_forPermissions(Activity, int)
),
AND location services should be enabled (see isLocationEnabledForScanning_byOsServices()
and isLocationEnabledForScanning_byOsServices()
).
true
if scan started, false>
otherwise - usually this means this manager is not BleManagerState.ON
.BluetoothEnabler
public final boolean startScan(ScanOptions options)
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()
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)
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 BleDevice.unbond()
,
on each device individually.public final void disconnectAll()
BleDeviceState.BLE_CONNECTED
.
Essentially a convenience method for calling BleDevice.disconnect()
,
on each device individually.public final void disconnectAll_remote()
disconnectAll()
but drills down to BleDevice.disconnect_remote()
instead.public final void undiscoverAll()
BleDeviceState.DISCOVERED
.
Essentially a convenience method for calling BleDevice.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 startScan()
or overloads, 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()
startScan()
(or overloads), 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 startScan()
.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.public final boolean isLocationEnabledForScanning_byRuntimePermissions()
true
if you're either pre-Android-M, or app has runtime permissions enabled by checking
*
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 startScan()
or overloads.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()
BleManagerConfig.autoPauseResumeDetection
is set to true
, which is the default.
The below comment only applies if the autoPauseResumeDetection is set to false
.
Opposite of onPause()
, to be called from your override of Activity.onResume()
for each Activity
in your application. See comment for onPause()
for a similar explanation for why you should call this method.public final void onPause()
BleManagerConfig.autoPauseResumeDetection
is set to true
, which is the default.
The below comment only applies if the autoPauseResumeDetection is set to false
.
It's generally recommended to call this in your override of 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 void shutdown()
get(Context)
, or get(Context, BleManagerConfig)
again.BleManagerConfig.blockingShutdown
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 stopPeriodicScan()
and stopScan()
for you.public final void stopScan()
startScan()
.public final void stopScan(ScanFilter filter)
stopScan()
but also unregisters any filter supplied to various overloads of startScan()
.
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.public final BleDevice getDevice(java.lang.String macAddress)
BleDeviceState.DISCOVERED
device by MAC address, or BleDevice.NULL
if there is no such device.public final boolean hasDevice(java.lang.String macAddress)
getDevice(String)
returns BleDevice.NULL
.public final boolean hasDevice(BleDevice device)
hasDevice(String)
.public final BleDevice getDevice(BleDeviceState state)
BleDevice.NULL
if no match is found.public final boolean hasDevice(BleDeviceState state)
public final BleDevice getDevice(java.lang.Object... query)
BleDevice.NULL
if no match is found.
See BleDevice.is(Object...)
for the query format.public final boolean hasDevice(java.lang.Object... query)
BleDevice.is(Object...)
for the query format.public final BleDevice getDevice(int mask_BleDeviceState)
true
for BleDevice.isAny(int)
, or BleDevice.NULL
if no such device is found.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 final java.util.List<BleDevice> getDevices(android.content.Intent intentFromScan)
ArrayList
of BleDevice
s from the Intent
which was delivered as a result of calling startScan(ScanOptions)
when using a
PendingIntent
.public final void getDevices(ForEach_Void<BleDevice> forEach)
getDevices()
or getDevices_List()
.public final void getDevices(ForEach_Void<BleDevice> forEach, BleDeviceState state)
getDevices(ForEach_Void)
but will only return devices
in the given state provided.public final void getDevices(ForEach_Breakable<BleDevice> forEach)
getDevices(ForEach_Void)
if you need to break out of the iteration at any point.public final void getDevices(ForEach_Breakable<BleDevice> forEach, BleDeviceState state)
getDevices(ForEach_Void, BleDeviceState)
if you need to break out of the iteration at any point.public final java.util.Iterator<java.lang.String> getDevices_previouslyConnected()
public final java.util.Set<BleDevice> getDevices_bonded()
Set
of currently bonded devices. This simply calls
BluetoothAdapter.getBondedDevices()
, and wraps all bonded devices into separate
BleDevice
classes.
NOTE: If the Bluetooth radio is turned off, some android devices return null
. In this case,
SweetBlue will just return an empty list.public final BleDeviceIterator getDevices()
BleDeviceState.ADVERTISING
or BleDeviceState.BLE_CONNECTED
.public final BleDeviceIterator getDevices_sorted()
getDevices()
, but with the devices sorted using BleManagerConfig.defaultListComparator
, which
by default sorts by BleDevice.getName_debug()
.public final java.util.List<BleDevice> getDevices_List()
getDevices()
that returns a List
for you.public final java.util.List<BleDevice> getDevices_List_sorted()
getDevices_List()
, but sorts the list using BleManagerConfig.defaultListComparator
.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()
startScan()
or newDevice(String)
(or overloads) then this will return false.public final BleDeviceIterator getDevices(BleDeviceState state)
getDevice(BleDeviceState)
except returns all matching devices.public final java.util.List<BleDevice> getDevices_List(BleDeviceState state)
getDevices(BleDeviceState)
that returns a List
for you.public final java.util.List<BleDevice> getDevices_List_sorted(BleDeviceState state)
getDevices_List(BleDeviceState)
except the list is sorted using BleManagerConfig.defaultListComparator
.public final BleDeviceIterator getDevices(java.lang.Object... query)
getDevice(Object...)
except returns all matching devices.
See BleDevice.is(Object...)
for the query format.public final java.util.List<BleDevice> getDevices_List(java.lang.Object... query)
getDevices(Object...)
that returns a List
for you.public final java.util.List<BleDevice> getDevices_List_sorted(java.lang.Object... query)
getDevices_List(Object...)
except the list is sorted using BleManagerConfig.defaultListComparator
.public final BleDeviceIterator getDevices(int mask_BleDeviceState)
getDevices()
except filters using BleDevice.isAny(int)
.public final java.util.List<BleDevice> getDevices_List(int mask_BleDeviceState)
getDevices(int)
that returns a List
for you.public final java.util.List<BleDevice> getDevices_List_sorted(int mask_BleDeviceState)
getDevices_List(int)
except the list is sorted using BleManagerConfig.defaultListComparator
.public final void removeDeviceFromCache(BleDevice device)
BleDevice
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()
BleDevice
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 BleServer getServer()
getServer(IncomingListener)
without any initial set-up parameters.public final BleServer getServer(IncomingListener incomingListener)
BleServer
instance. which for now at least is a singleton.public final BleServer getServer(GattDatabase gattDatabase)
getServer(GattDatabase, AddServiceListener)
, with no AddServiceListener
set.public final BleServer getServer(GattDatabase gattDatabase, AddServiceListener addServiceListener)
getServer(IncomingListener, GattDatabase, AddServiceListener)
, with no IncomingListener
set.public final BleServer getServer(IncomingListener incomingListener, GattDatabase gattDatabase, AddServiceListener addServiceListener)
BleServer
instance. This is now the preferred method to retrieve the server instance.public final BleDevice newDevice(java.lang.String macAddress)
newDevice(String, String, BleDeviceConfig)
but uses an empty string for the name
and passes a null
BleDeviceConfig
, which results in inherited options from BleManagerConfig
.public final BleDevice newDevice(android.bluetooth.BluetoothDevice nativeDevice)
newDevice(String)
, but this method accepts a native BluetoothDevice
as an argument. This should only
ever really be used when using a PendingIntent
scan.public final BleDevice newDevice(android.bluetooth.BluetoothDevice nativeDevice, BleDeviceConfig config)
newDevice(BluetoothDevice)
, but allows passing in a BleDeviceConfig
as well.public final BleDevice newDevice(java.lang.String macAddress, java.lang.String name)
newDevice(String)
but allows a custom name also.public final BleDevice newDevice(java.lang.String macAddress, BleDeviceConfig config)
newDevice(String)
but passes a BleDeviceConfig
to be used as well.public final BleDevice newDevice(java.lang.String macAddress, java.lang.String name, BleDeviceConfig config)
newDevice(String, String, byte[], BleDeviceConfig)
.public final BleDevice newDevice(java.lang.String macAddress, java.lang.String name, byte[] scanRecord, BleDeviceConfig config)
BleDevice
or returns an existing one if the macAddress matches.
GenericListener_Void.onEvent(Event)
will be called if a new device
is created.
BleDevice.isNull()
check on this method's return value just in case. Android
documentation says that underlying stack will always return a valid BluetoothDevice
instance (which is required to create a valid BleDevice
instance), but you really never know.public final boolean undiscover(BleDevice 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 BleDevice.equals(BleDevice)
(i.e. by mac address).public final void clearQueue()
public final void clearSharedPreferences(BleDevice 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