public final class ScanOptions
extends java.lang.Object
BleManager.startScan(ScanOptions)
.Constructor and Description |
---|
ScanOptions() |
ScanOptions(DiscoveryListener listener_nullable) |
ScanOptions(ScanFilter scanFilter) |
ScanOptions(ScanFilter scanFilter,
DiscoveryListener listener_nullable) |
Modifier and Type | Method and Description |
---|---|
ScanOptions |
asHighPriority(boolean highPriority)
This will set the scan to be of the highest priority.
|
ScanOptions |
forceIndefinite(boolean force)
Force a indefinite scan.
|
ScanFilter.ApplyMode |
getApplyMode() |
DiscoveryListener |
getDiscoveryListener() |
Interval |
getPauseTime() |
android.app.PendingIntent |
getPendingIntent() |
ScanFilter |
getScanFilter() |
Interval |
getScanTime() |
boolean |
isContinuous()
Returns
true if this instance is a periodic scan, or indefinite. |
boolean |
isForceIndefinite() |
boolean |
isPeriodic() |
boolean |
isPriorityScan() |
ScanOptions |
scanFor(Interval time)
Scan for the specified amount of time.
|
ScanOptions |
scanInfinitely()
Scan indefinitely until
BleManager.stopScan() is called. |
ScanOptions |
scanPeriodically(Interval scanTime,
Interval pauseTime)
Do a periodic scan.
|
ScanOptions |
withDiscoveryListener(DiscoveryListener listener)
Set a
DiscoveryListener for this scan. |
ScanOptions |
withPendingIntent(android.app.PendingIntent pendingIntent)
NOTE: This will only work for devices running android 8 (Oreo) or higher (API level 26+).
|
ScanOptions |
withScanFilter(ScanFilter filter)
Set a
ScanFilter for this scan. |
ScanOptions |
withScanFilterApplyMode(ScanFilter.ApplyMode applyMode)
Set a
ScanFilter.ApplyMode for this scan. |
public ScanOptions()
public ScanOptions(ScanFilter scanFilter)
public ScanOptions(DiscoveryListener listener_nullable)
public ScanOptions(ScanFilter scanFilter, DiscoveryListener listener_nullable)
public final ScanOptions scanInfinitely()
BleManager.stopScan()
is called. If this is called after
scanPeriodically(Interval, Interval)
, this will override the periodic scan.public final ScanOptions scanFor(Interval time)
scanPeriodically(Interval, Interval)
instead.
If this is called after scanPeriodically(Interval, Interval)
, it will override the periodic scan.public final ScanOptions forceIndefinite(boolean force)
true
here, the scan will just run until you call
BleManager.stopScan()
. There's really no reason to do this, but it's left in here to be flexible.public final ScanOptions scanPeriodically(Interval scanTime, Interval pauseTime)
scanFor(Interval)
instead.public final ScanOptions withScanFilter(ScanFilter filter)
ScanFilter
for this scan.public final ScanOptions withScanFilterApplyMode(ScanFilter.ApplyMode applyMode)
ScanFilter.ApplyMode
for this scan.public final ScanOptions withDiscoveryListener(DiscoveryListener listener)
DiscoveryListener
for this scan.public final ScanOptions withPendingIntent(android.app.PendingIntent pendingIntent)
BleManager.startScan()
to know if a scan started.
NOTE 2: DiscoveryListener
is ignored when using this feature.
Set a PendingIntent
for the system to use as a callback to your application when
new devices are discovered. This is a special scan in that you will get back native
BluetoothDevice
instances in your activity/receiver. It is recommended
to use BleManager.getDevices(Intent)
to convert the native android bluetooth device instances
to BleDevice
instances for you.
To execute a scan properly, you need to create a PendingIntent like below:
PendingIntent pIntent = PendingIntent.getBroadcast(activity, 42, new Intent(activity, MyScanReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
You also must remember to create a class which extends BroadcastReceiver
, and this class must be
added to your AndroidManifest.xml file. eg:
<receiver android:name="com.myapp.MyScanReceiver" >
<intent-filter>
<action android:name="com.myapp.ACTION_FOUND" />
</intent-filter>
</receiver>
public final ScanOptions asHighPriority(boolean highPriority)
BleManager.stopScan()
.public final Interval getScanTime()
public final Interval getPauseTime()
public final ScanFilter getScanFilter()
public final ScanFilter.ApplyMode getApplyMode()
public final DiscoveryListener getDiscoveryListener()
public final android.app.PendingIntent getPendingIntent()
public final boolean isPeriodic()
public final boolean isPriorityScan()
public final boolean isForceIndefinite()
public boolean isContinuous()
true
if this instance is a periodic scan, or indefinite.