Package org.altbeacon.beacon
Class BeaconManager
- java.lang.Object
-
- org.altbeacon.beacon.BeaconManager
-
public class BeaconManager extends Object
A class used to set up interaction with beacons from anActivityorService. This class is used in conjunction withBeaconConsumerinterface, which provides a callback when theBeaconServiceis ready to use. Until this callback is made, ranging and monitoring of beacons is not possible. In the example below, an Activity implements theBeaconConsumerinterface, binds to the service, then when it gets the callback saying the service is ready, it starts ranging.public class RangingActivity extends Activity implements BeaconConsumer { protected static final String TAG = "RangingActivity"; private BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ranging); beaconManager.bind(this); } @Override protected void onDestroy() { super.onDestroy(); beaconManager.unbind(this); } @Override public void onBeaconServiceConnect() { beaconManager.setRangeNotifier(new RangeNotifier() { @Override public void didRangeBeaconsInRegion(Collectionbeacons, Region region) { if (beacons.size() > 0) { Log.i(TAG, "The first beacon I see is about "+beacons.iterator().next().getDistance()+" meters away."); } } }); try { beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null)); } catch (RemoteException e) { e.printStackTrace(); } } }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classBeaconManager.ServiceNotDeclaredException
-
Field Summary
Fields Modifier and Type Field Description protected static BeaconSimulatorbeaconSimulatorprotected RangeNotifierdataRequestNotifierstatic longDEFAULT_BACKGROUND_BETWEEN_SCAN_PERIODThe default duration in milliseconds spent not scanning between each Bluetooth scan cycle when no ranging/monitoring clients are in the foregroundstatic longDEFAULT_BACKGROUND_SCAN_PERIODThe default duration in milliseconds of the Bluetooth scan cycle when no ranging/monitoring clients are in the foregroundstatic longDEFAULT_EXIT_PERIODThe default duration in milliseconds of region exit timestatic longDEFAULT_FOREGROUND_BETWEEN_SCAN_PERIODThe default duration in milliseconds spent not scanning between each Bluetooth scan cyclestatic longDEFAULT_FOREGROUND_SCAN_PERIODThe default duration in milliseconds of the Bluetooth scan cycleprotected static StringdistanceModelUpdateUrlprotected Set<MonitorNotifier>monitorNotifiersprotected Set<RangeNotifier>rangeNotifiersprotected static ClassrssiFilterImplClassDefault class for rssi filter/calculation implementationprotected static BeaconManagersInstance
-
Constructor Summary
Constructors Modifier Constructor Description protectedBeaconManager(Context context)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddMonitorNotifier(MonitorNotifier notifier)Specifies a class that should be called each time theBeaconServicesees or stops seeing a Region of beacons.voidaddRangeNotifier(RangeNotifier notifier)Specifies a class that should be called each time theBeaconServicegets ranging data, which is nominally once per second when beacons are detected.voidapplySettings()Call this method if you are running the scanner service in a different process in order to synchronize any configuration settings, including BeaconParsers to the scannervoidbind(BeaconConsumer consumer)Binds an AndroidActivityorServiceto theBeaconService.booleancheckAvailability()Check if Bluetooth LE is supported by this Android device, and if so, make sure it is enabled.protected voidcheckIfMainProcess()voiddisableForegroundServiceScanning()Disables a foreground scanning service, if previously configured.voidenableForegroundServiceScanning(Notification notification, int notificationId)Configures the library to use a foreground service for bacon scanning.longgetBackgroundBetweenScanPeriod()booleangetBackgroundMode()longgetBackgroundScanPeriod()List<BeaconParser>getBeaconParsers()Gets a list of the active beaconParsers.static BeaconSimulatorgetBeaconSimulator()protected RangeNotifiergetDataRequestNotifier()static StringgetDistanceModelUpdateUrl()longgetForegroundBetweenScanPeriod()longgetForegroundScanPeriod()NotificationgetForegroundServiceNotification()intgetForegroundServiceNotificationId()static BeaconManagergetInstanceForApplication(Context context)An accessor for the singleton instance of this class.static booleangetManifestCheckingDisabled()Returns whether manifest checking is disabledCollection<Region>getMonitoredRegions()MonitorNotifiergetMonitoringNotifier()Deprecated.replaced by (@link #getMonitorNotifiers)Set<MonitorNotifier>getMonitoringNotifiers()Read-only access to the registeredMonitorNotifierinstancesNonBeaconLeScanCallbackgetNonBeaconLeScanCallback()Collection<Region>getRangedRegions()RangeNotifiergetRangingNotifier()Deprecated.replaced by (@link #getRangeNotifiers)Set<RangeNotifier>getRangingNotifiers()Read-only access to the registeredRangeNotifierinstancesstatic longgetRegionExitPeriod()Get region exit millisecondsstatic ClassgetRssiFilterImplClass()booleangetScheduledScanJobsEnabled()static booleanisAndroidLScanningDisabled()Determines if Android L Scanning is disabled by user selectionbooleanisAnyConsumerBound()Tells you if the any beacon consumer is bound to the servicebooleanisBackgroundModeUninitialized()booleanisBound(BeaconConsumer consumer)Tells you if the passed beacon consumer is bound to the servicebooleanisMainProcess()Determines if this BeaconManager instance is associated with the main application process that hosts the user interface.booleanisRegionStatePersistenceEnabled()Indicates whether region state preservation is enabledbooleanisScannerInDifferentProcess()Determines if this BeaconManager instance is not part of the process hosting the beacon scanning service.static voidlogDebug(String tag, String message)Deprecated.This will be removed in a later release.static voidlogDebug(String tag, String message, Throwable t)Deprecated.This will be removed in a later release.voidremoveAllMonitorNotifiers()Remove all the Monitor Notifiers.voidremoveAllRangeNotifiers()Remove all the Range Notifiers.booleanremoveMonitoreNotifier(MonitorNotifier notifier)Deprecated.Misspelled.booleanremoveMonitorNotifier(MonitorNotifier notifier)Specifies a class to remove from the array ofMonitorNotifier.booleanremoveRangeNotifier(RangeNotifier notifier)Specifies a class to remove from the array ofRangeNotifiervoidrequestStateForRegion(Region region)Requests the current in/out state on the specified region.static voidsetAndroidLScanningDisabled(boolean disabled)Allows disabling use of Android L BLE Scanning APIs on devices with API 21+ If set to false (default), devices with API 21+ will use the Android L APIs to scan for beaconsvoidsetBackgroundBetweenScanPeriod(long p)Sets the duration in milliseconds spent not scanning between each Bluetooth LE scan cycle when no ranging/monitoring clients are in the foregroundvoidsetBackgroundMode(boolean backgroundMode)This method notifies the beacon service that the application is either moving to background mode or foreground mode.voidsetBackgroundScanPeriod(long p)Sets the duration in milliseconds of each Bluetooth LE scan cycle to look for beacons.static voidsetBeaconSimulator(BeaconSimulator beaconSimulator)protected voidsetDataRequestNotifier(RangeNotifier notifier)static voidsetDebug(boolean debug)Set to true if you want to show library debugging.static voidsetDistanceModelUpdateUrl(String url)voidsetEnableScheduledScanJobs(boolean enabled)Configures using a `ScanJob` run with the `JobScheduler` to perform scans rather than using a long-running `BeaconService` to do so.voidsetForegroundBetweenScanPeriod(long p)Sets the duration in milliseconds between each Bluetooth LE scan cycle to look for beacons.voidsetForegroundScanPeriod(long p)Sets the duration in milliseconds of each Bluetooth LE scan cycle to look for beacons.static voidsetManifestCheckingDisabled(boolean disabled)Allows disabling check of manifest for proper configuration of service.voidsetMaxTrackingAge(int maxTrackingAge)Set the period of time, in which a beacon did not receive new measurementsvoidsetMonitorNotifier(MonitorNotifier notifier)Deprecated.voidsetNonBeaconLeScanCallback(NonBeaconLeScanCallback callback)voidsetRangeNotifier(RangeNotifier notifier)Deprecated.replaced by (@link #addRangeNotifier)static voidsetRegionExitPeriod(long regionExitPeriod)Set region exit period in millisecondsvoidsetRegionStatePeristenceEnabled(boolean enabled)Deprecated.Misspelled.voidsetRegionStatePersistenceEnabled(boolean enabled)Turns off saving the state of monitored regions to persistent storage so it is retained over app restarts.static voidsetRssiFilterImplClass(Class c)voidsetScannerInSameProcess(boolean isScanner)Reserved for internal use by the library.static voidsetsManifestCheckingDisabled(boolean disabled)Deprecated.static voidsetUseTrackingCache(boolean useTrackingCache)Allow the library to use a tracking cachevoidstartMonitoringBeaconsInRegion(List<Region> regions)voidstartMonitoringBeaconsInRegion(Region region)Tells theBeaconServiceto start looking for beacons that match the passedRegionobject.voidstartRangingBeaconsInRegion(List<Region> regions)voidstartRangingBeaconsInRegion(Region region)Tells theBeaconServiceto start looking for beacons that match the passedRegionobject, and providing updates on the estimated mDistance every seconds while beacons in the Region are visible.voidstopAllMonitoringBeaconsInRegion()voidstopAllRangingBeaconsInRegion()voidstopMonitoringBeaconsInRegion(List<Region> regions)voidstopMonitoringBeaconsInRegion(Region region)Tells theBeaconServiceto stop looking for beacons that match the passedRegionobject.voidstopRangingBeaconsInRegion(List<Region> regions)voidstopRangingBeaconsInRegion(Region region)Tells theBeaconServiceto stop looking for beacons that match the passedRegionobject and providing mDistance information for them.protected voidsyncSettingsToService()voidunbind(BeaconConsumer consumer)Unbinds an AndroidActivityorServiceto theBeaconService.voidupdateScanPeriods()Updates an already running scan with scanPeriod/betweenScanPeriod according to Background/Foreground state.
-
-
-
Field Detail
-
sInstance
@Nullable protected static volatile BeaconManager sInstance
-
rangeNotifiers
@NonNull protected final Set<RangeNotifier> rangeNotifiers
-
dataRequestNotifier
@Nullable protected RangeNotifier dataRequestNotifier
-
monitorNotifiers
@NonNull protected final Set<MonitorNotifier> monitorNotifiers
-
DEFAULT_FOREGROUND_SCAN_PERIOD
public static final long DEFAULT_FOREGROUND_SCAN_PERIOD
The default duration in milliseconds of the Bluetooth scan cycle- See Also:
- Constant Field Values
-
DEFAULT_FOREGROUND_BETWEEN_SCAN_PERIOD
public static final long DEFAULT_FOREGROUND_BETWEEN_SCAN_PERIOD
The default duration in milliseconds spent not scanning between each Bluetooth scan cycle- See Also:
- Constant Field Values
-
DEFAULT_BACKGROUND_SCAN_PERIOD
public static final long DEFAULT_BACKGROUND_SCAN_PERIOD
The default duration in milliseconds of the Bluetooth scan cycle when no ranging/monitoring clients are in the foreground- See Also:
- Constant Field Values
-
DEFAULT_BACKGROUND_BETWEEN_SCAN_PERIOD
public static final long DEFAULT_BACKGROUND_BETWEEN_SCAN_PERIOD
The default duration in milliseconds spent not scanning between each Bluetooth scan cycle when no ranging/monitoring clients are in the foreground- See Also:
- Constant Field Values
-
DEFAULT_EXIT_PERIOD
public static final long DEFAULT_EXIT_PERIOD
The default duration in milliseconds of region exit time- See Also:
- Constant Field Values
-
beaconSimulator
@Nullable protected static BeaconSimulator beaconSimulator
-
distanceModelUpdateUrl
protected static String distanceModelUpdateUrl
-
rssiFilterImplClass
protected static Class rssiFilterImplClass
Default class for rssi filter/calculation implementation
-
-
Constructor Detail
-
BeaconManager
protected BeaconManager(@NonNull Context context)
-
-
Method Detail
-
setDebug
public static void setDebug(boolean debug)
Set to true if you want to show library debugging.- Parameters:
debug- True turn on all logs for this library to be printed out to logcat. False turns off detailed logging.. This is a convenience method that calls setLogger to a verbose logger and enables verbose logging. For more fine grained control, use:LogManager.setLogger(org.altbeacon.beacon.logging.Logger)instead.
-
setForegroundScanPeriod
public void setForegroundScanPeriod(long p)
Sets the duration in milliseconds of each Bluetooth LE scan cycle to look for beacons. This function is used to setup the period before callingbind(org.altbeacon.beacon.BeaconConsumer)or when switching between background/foreground. To have it effect on an already running scan (when the next cycle starts), callupdateScanPeriods()- Parameters:
p-
-
setForegroundBetweenScanPeriod
public void setForegroundBetweenScanPeriod(long p)
Sets the duration in milliseconds between each Bluetooth LE scan cycle to look for beacons. This function is used to setup the period before callingbind(org.altbeacon.beacon.BeaconConsumer)or when switching between background/foreground. To have it effect on an already running scan (when the next cycle starts), callupdateScanPeriods()- Parameters:
p-
-
setBackgroundScanPeriod
public void setBackgroundScanPeriod(long p)
Sets the duration in milliseconds of each Bluetooth LE scan cycle to look for beacons. This function is used to setup the period before callingbind(org.altbeacon.beacon.BeaconConsumer)or when switching between background/foreground. To have it effect on an already running scan (when the next cycle starts), callupdateScanPeriods()- Parameters:
p-
-
setBackgroundBetweenScanPeriod
public void setBackgroundBetweenScanPeriod(long p)
Sets the duration in milliseconds spent not scanning between each Bluetooth LE scan cycle when no ranging/monitoring clients are in the foreground- Parameters:
p-
-
setRegionExitPeriod
public static void setRegionExitPeriod(long regionExitPeriod)
Set region exit period in milliseconds- Parameters:
regionExitPeriod-
-
getRegionExitPeriod
public static long getRegionExitPeriod()
Get region exit milliseconds- Returns:
- exit region period in milliseconds
-
getInstanceForApplication
@NonNull public static BeaconManager getInstanceForApplication(@NonNull Context context)
An accessor for the singleton instance of this class. A context must be provided, but if you need to use it from a non-Activity or non-Service class, you can attach it to another singleton or a subclass of the Android Application class.
-
isMainProcess
public boolean isMainProcess()
Determines if this BeaconManager instance is associated with the main application process that hosts the user interface. This is normally true unless the scanning service or another servide is running in a separate process.- Returns:
-
isScannerInDifferentProcess
public boolean isScannerInDifferentProcess()
Determines if this BeaconManager instance is not part of the process hosting the beacon scanning service. This is normally false, except when scanning is hosted in a different process. This will always return false until the scanning service starts up, at which time it will be known if it is in a different process.- Returns:
-
setScannerInSameProcess
public void setScannerInSameProcess(boolean isScanner)
Reserved for internal use by the library.
-
checkIfMainProcess
protected void checkIfMainProcess()
-
getBeaconParsers
@NonNull public List<BeaconParser> getBeaconParsers()
Gets a list of the active beaconParsers.- Returns:
- list of active BeaconParsers
-
checkAvailability
public boolean checkAvailability() throws BleNotAvailableExceptionCheck if Bluetooth LE is supported by this Android device, and if so, make sure it is enabled.- Returns:
- false if it is supported and not enabled
- Throws:
BleNotAvailableException- if Bluetooth LE is not supported. (Note: The Android emulator will do this)
-
bind
public void bind(@NonNull BeaconConsumer consumer)Binds an AndroidActivityorServiceto theBeaconService. TheActivityorServicemust implement thebeaconConsumerinterface so that it can get a callback when the service is ready to use.- Parameters:
consumer- theActivityorServicethat will receive the callback when the service is ready.
-
unbind
public void unbind(@NonNull BeaconConsumer consumer)Unbinds an AndroidActivityorServiceto theBeaconService. This should typically be called in the onDestroy() method.- Parameters:
consumer- theActivityorServicethat no longer needs to use the service.
-
isBound
public boolean isBound(@NonNull BeaconConsumer consumer)Tells you if the passed beacon consumer is bound to the service- Parameters:
consumer-- Returns:
-
isAnyConsumerBound
public boolean isAnyConsumerBound()
Tells you if the any beacon consumer is bound to the service- Returns:
-
setBackgroundMode
public void setBackgroundMode(boolean backgroundMode)
This method notifies the beacon service that the application is either moving to background mode or foreground mode. When in background mode, BluetoothLE scans to look for beacons are executed less frequently in order to save battery life. The specific scan rates for background and foreground operation are set by the defaults below, but may be customized. When ranging in the background, the time between updates will be much less frequent than in the foreground. Updates will come every time interval equal to the sum total of the BackgroundScanPeriod and the BackgroundBetweenScanPeriod.- Parameters:
backgroundMode- true indicates the app is in the background- See Also:
DEFAULT_FOREGROUND_SCAN_PERIOD,setForegroundScanPeriod(long p),setForegroundBetweenScanPeriod(long p),setBackgroundScanPeriod(long p),setBackgroundBetweenScanPeriod(long p)
-
setEnableScheduledScanJobs
public void setEnableScheduledScanJobs(boolean enabled)
Configures using a `ScanJob` run with the `JobScheduler` to perform scans rather than using a long-running `BeaconService` to do so. Calling with true on devices older than Android L (5.0) will not apply the change as the JobScheduler is not available. This value defaults to true on Android O+ and false on devices with older OS versions. Accepting the default value of false is recommended on Android N and earlier because otherwise beacon scans may be run only once every 15 minutes in the background, and no low power scans may be performed between scanning cycles. Setting this value to false will disable ScanJobs when the app is run on Android 8+, which can prohibit delivery of callbacks when the app is in the background unless the scanning process is running in a foreground service. This method may only be called if bind() has not yet been called, otherwise an `IllegalStateException` is thown.- Parameters:
enabled-
-
getScheduledScanJobsEnabled
public boolean getScheduledScanJobsEnabled()
-
getBackgroundMode
public boolean getBackgroundMode()
-
getBackgroundScanPeriod
public long getBackgroundScanPeriod()
-
getBackgroundBetweenScanPeriod
public long getBackgroundBetweenScanPeriod()
-
getForegroundScanPeriod
public long getForegroundScanPeriod()
-
getForegroundBetweenScanPeriod
public long getForegroundBetweenScanPeriod()
-
isBackgroundModeUninitialized
public boolean isBackgroundModeUninitialized()
- Returns:
- indicator of whether any calls have yet been made to set the background mode
-
setRangeNotifier
@Deprecated public void setRangeNotifier(@Nullable RangeNotifier notifier)
Deprecated.replaced by (@link #addRangeNotifier)Specifies a class that should be called each time theBeaconServicegets ranging data, which is nominally once per second when beacons are detected. IMPORTANT: Only one RangeNotifier may be active for a given application. If two different activities or services set different RangeNotifier instances, the last one set will receive all the notifications.- Parameters:
notifier- TheRangeNotifierto register.- See Also:
RangeNotifier
-
addRangeNotifier
public void addRangeNotifier(@NonNull RangeNotifier notifier)Specifies a class that should be called each time theBeaconServicegets ranging data, which is nominally once per second when beacons are detected. Permits to register severalRangeNotifierobjects. The notifier must be unregistered using (@link #removeRangeNotifier)- Parameters:
notifier- TheRangeNotifierto register.- See Also:
RangeNotifier
-
removeRangeNotifier
public boolean removeRangeNotifier(@NonNull RangeNotifier notifier)Specifies a class to remove from the array ofRangeNotifier- Parameters:
notifier- TheRangeNotifierto unregister.- See Also:
RangeNotifier
-
removeAllRangeNotifiers
public void removeAllRangeNotifiers()
Remove all the Range Notifiers.
-
setMonitorNotifier
@Deprecated public void setMonitorNotifier(@Nullable MonitorNotifier notifier)
Deprecated.Specifies a class that should be called each time theBeaconServicesees or stops seeing a Region of beacons. IMPORTANT: Only one MonitorNotifier may be active for a given application. If two different activities or services set different MonitorNotifier instances, the last one set will receive all the notifications.- Parameters:
notifier- TheMonitorNotifierto register.- See Also:
MonitorNotifier,startMonitoringBeaconsInRegion(Region),Region
-
addMonitorNotifier
public void addMonitorNotifier(@NonNull MonitorNotifier notifier)Specifies a class that should be called each time theBeaconServicesees or stops seeing a Region of beacons. Permits to register severalMonitorNotifierobjects. Unregister the notifier usingremoveMonitoreNotifier(org.altbeacon.beacon.MonitorNotifier)- Parameters:
notifier- TheMonitorNotifierto register.- See Also:
MonitorNotifier,startMonitoringBeaconsInRegion(Region),Region
-
removeMonitoreNotifier
@Deprecated public boolean removeMonitoreNotifier(@NonNull MonitorNotifier notifier)
Deprecated.Misspelled. Replaced byremoveMonitorNotifier(org.altbeacon.beacon.MonitorNotifier)
-
removeMonitorNotifier
public boolean removeMonitorNotifier(@NonNull MonitorNotifier notifier)Specifies a class to remove from the array ofMonitorNotifier.- Parameters:
notifier- TheMonitorNotifierto unregister.- See Also:
MonitorNotifier,startMonitoringBeaconsInRegion(Region),Region
-
removeAllMonitorNotifiers
public void removeAllMonitorNotifiers()
Remove all the Monitor Notifiers.
-
setRegionStatePeristenceEnabled
@Deprecated public void setRegionStatePeristenceEnabled(boolean enabled)
Deprecated.Misspelled. Replaced bysetRegionStatePersistenceEnabled(boolean)
-
setRegionStatePersistenceEnabled
public void setRegionStatePersistenceEnabled(boolean enabled)
Turns off saving the state of monitored regions to persistent storage so it is retained over app restarts. Defaults to enabled. When enabled, there will not be an "extra" region entry event when the app starts up and a beacon for a monitored region was previously visible within the past 15 minutes. Note that there is a limit to 50 monitored regions that may be persisted. If more than 50 regions are monitored, state is not persisted for any.- Parameters:
enabled- true to enable the region state persistence, false to disable it.
-
isRegionStatePersistenceEnabled
public boolean isRegionStatePersistenceEnabled()
Indicates whether region state preservation is enabled- Returns:
-
requestStateForRegion
public void requestStateForRegion(@NonNull Region region)Requests the current in/out state on the specified region. If the region is being monitored, this will cause an asynchronous callback on the `MonitorNotifier`'s `didDetermineStateForRegion` method. If it is not a monitored region, it will be ignored.- Parameters:
region-
-
startRangingBeaconsInRegion
public void startRangingBeaconsInRegion(@NonNull List<Region> regions) throws RemoteException- Throws:
RemoteException
-
stopRangingBeaconsInRegion
public void stopRangingBeaconsInRegion(@NonNull List<Region> regions) throws RemoteException- Throws:
RemoteException
-
stopAllRangingBeaconsInRegion
public void stopAllRangingBeaconsInRegion() throws RemoteException- Throws:
RemoteException
-
startRangingBeaconsInRegion
public void startRangingBeaconsInRegion(@NonNull Region region) throws RemoteExceptionTells theBeaconServiceto start looking for beacons that match the passedRegionobject, and providing updates on the estimated mDistance every seconds while beacons in the Region are visible. Note that the Region's unique identifier must be retained to later call the stopRangingBeaconsInRegion method.- Parameters:
region-- Throws:
RemoteException- See Also:
setRangeNotifier(RangeNotifier),stopRangingBeaconsInRegion(Region region),RangeNotifier,Region
-
stopRangingBeaconsInRegion
public void stopRangingBeaconsInRegion(@NonNull Region region) throws RemoteExceptionTells theBeaconServiceto stop looking for beacons that match the passedRegionobject and providing mDistance information for them.- Parameters:
region-- Throws:
RemoteException- See Also:
setMonitorNotifier(MonitorNotifier notifier),startMonitoringBeaconsInRegion(Region region),MonitorNotifier,Region
-
applySettings
public void applySettings()
Call this method if you are running the scanner service in a different process in order to synchronize any configuration settings, including BeaconParsers to the scanner- See Also:
isScannerInDifferentProcess()
-
syncSettingsToService
protected void syncSettingsToService()
-
startMonitoringBeaconsInRegion
public void startMonitoringBeaconsInRegion(@NonNull List<Region> regions) throws RemoteException- Throws:
RemoteException
-
stopMonitoringBeaconsInRegion
public void stopMonitoringBeaconsInRegion(@NonNull List<Region> regions) throws RemoteException- Throws:
RemoteException
-
stopAllMonitoringBeaconsInRegion
public void stopAllMonitoringBeaconsInRegion() throws RemoteException- Throws:
RemoteException
-
startMonitoringBeaconsInRegion
public void startMonitoringBeaconsInRegion(@NonNull Region region) throws RemoteExceptionTells theBeaconServiceto start looking for beacons that match the passedRegionobject. Note that the Region's unique identifier must be retained to later call the stopMonitoringBeaconsInRegion method.- Parameters:
region-- Throws:
RemoteException- See Also:
setMonitorNotifier(MonitorNotifier),stopMonitoringBeaconsInRegion(Region region),MonitorNotifier,Region
-
stopMonitoringBeaconsInRegion
public void stopMonitoringBeaconsInRegion(@NonNull Region region) throws RemoteExceptionTells theBeaconServiceto stop looking for beacons that match the passedRegionobject. Note that the Region's unique identifier is used to match it to an existing monitored Region.- Parameters:
region-- Throws:
RemoteException- See Also:
setMonitorNotifier(MonitorNotifier),startMonitoringBeaconsInRegion(Region region),MonitorNotifier,Region
-
updateScanPeriods
public void updateScanPeriods() throws RemoteExceptionUpdates an already running scan with scanPeriod/betweenScanPeriod according to Background/Foreground state. Change will take effect on the start of the next scan cycle.- Throws:
RemoteException- - If the BeaconManager is not bound to the service.
-
getMonitoringNotifier
@Deprecated @Nullable public MonitorNotifier getMonitoringNotifier()
Deprecated.replaced by (@link #getMonitorNotifiers)- Returns:
- the first registered monitorNotifier
-
getMonitoringNotifiers
@NonNull public Set<MonitorNotifier> getMonitoringNotifiers()
Read-only access to the registeredMonitorNotifierinstancesThis provides a thread-safe "read-only" view of the
Setof registered monitor notifiers. Attempts to modify the returned set, or its iterator, will throw anUnsupportedOperationException. Modifications to the underlying set should be made throughaddMonitorNotifier(MonitorNotifier)andremoveMonitorNotifier(MonitorNotifier).- Returns:
- a thread-safe unmodifiable view
providing "read-only" access to the registered
MonitorNotifierinstances - See Also:
addMonitorNotifier(MonitorNotifier),removeMonitorNotifier(MonitorNotifier),Collections.unmodifiableSet(Set)
-
getRangingNotifier
@Deprecated @Nullable public RangeNotifier getRangingNotifier()
Deprecated.replaced by (@link #getRangeNotifiers)- Returns:
- the first registered rangeNotifier
-
getRangingNotifiers
@NonNull public Set<RangeNotifier> getRangingNotifiers()
Read-only access to the registeredRangeNotifierinstancesThis provides a thread-safe "read-only" view of the
Setof registered range notifiers. Attempts to modify the returned set, or its iterator, will throw anUnsupportedOperationException. Modifications to the underlying set should be made throughaddRangeNotifier(RangeNotifier)andremoveRangeNotifier(RangeNotifier).- Returns:
- a thread-safe unmodifiable view
providing "read-only" access to the registered
RangeNotifierinstances - See Also:
addRangeNotifier(RangeNotifier),removeRangeNotifier(RangeNotifier),Collections.unmodifiableSet(Set)
-
getMonitoredRegions
@NonNull public Collection<Region> getMonitoredRegions()
- Returns:
- the list of regions currently being monitored
-
getRangedRegions
@NonNull public Collection<Region> getRangedRegions()
- Returns:
- the list of regions currently being ranged
-
logDebug
@Deprecated public static void logDebug(String tag, String message)
Deprecated.This will be removed in a later release. UseLogManager.d(String, String, Object...)instead.Convenience method for logging debug by the library- Parameters:
tag-message-
-
logDebug
@Deprecated public static void logDebug(String tag, String message, Throwable t)
Deprecated.This will be removed in a later release. UseLogManager.d(Throwable, String, String, Object...)instead.Convenience method for logging debug by the library- Parameters:
tag-message-t-
-
getDistanceModelUpdateUrl
public static String getDistanceModelUpdateUrl()
-
setDistanceModelUpdateUrl
public static void setDistanceModelUpdateUrl(@NonNull String url)
-
setRssiFilterImplClass
public static void setRssiFilterImplClass(@NonNull Class c)
-
getRssiFilterImplClass
public static Class getRssiFilterImplClass()
-
setUseTrackingCache
public static void setUseTrackingCache(boolean useTrackingCache)
Allow the library to use a tracking cache- Parameters:
useTrackingCache-
-
setMaxTrackingAge
public void setMaxTrackingAge(int maxTrackingAge)
Set the period of time, in which a beacon did not receive new measurements- Parameters:
maxTrackingAge- in milliseconds
-
setBeaconSimulator
public static void setBeaconSimulator(BeaconSimulator beaconSimulator)
-
getBeaconSimulator
@Nullable public static BeaconSimulator getBeaconSimulator()
-
setDataRequestNotifier
protected void setDataRequestNotifier(@Nullable RangeNotifier notifier)
-
getDataRequestNotifier
@Nullable protected RangeNotifier getDataRequestNotifier()
-
getNonBeaconLeScanCallback
@Nullable public NonBeaconLeScanCallback getNonBeaconLeScanCallback()
-
setNonBeaconLeScanCallback
public void setNonBeaconLeScanCallback(@Nullable NonBeaconLeScanCallback callback)
-
isAndroidLScanningDisabled
public static boolean isAndroidLScanningDisabled()
Determines if Android L Scanning is disabled by user selection- Returns:
-
setAndroidLScanningDisabled
public static void setAndroidLScanningDisabled(boolean disabled)
Allows disabling use of Android L BLE Scanning APIs on devices with API 21+ If set to false (default), devices with API 21+ will use the Android L APIs to scan for beacons- Parameters:
disabled-
-
setsManifestCheckingDisabled
@Deprecated public static void setsManifestCheckingDisabled(boolean disabled)
Deprecated.Deprecated misspelled method- Parameters:
disabled-- See Also:
setManifestCheckingDisabled(boolean)
-
setManifestCheckingDisabled
public static void setManifestCheckingDisabled(boolean disabled)
Allows disabling check of manifest for proper configuration of service. Useful for unit testing- Parameters:
disabled-
-
getManifestCheckingDisabled
public static boolean getManifestCheckingDisabled()
Returns whether manifest checking is disabled
-
enableForegroundServiceScanning
public void enableForegroundServiceScanning(Notification notification, int notificationId) throws IllegalStateException
Configures the library to use a foreground service for bacon scanning. This allows nearly constant scanning on most Android versions to get around background limits, and displays an icon to the user to indicate that the app is doing something in the background, even on Android 8+. This will disable the user of the JobScheduler on Android 8 to do scans. Note that this method does not by itself enable constant scanning. The scan intervals will work as normal and must be configurd to specific values depending on how often you wish to scan.- Parameters:
notification- - the notification that will be displayed when beacon scanning is active, along with the icon that shows up in the status bar.- Throws:
IllegalStateException- if called after consumers are already bound to the scanning service- See Also:
setForegroundScanPeriod(long),This method requires a notification to display a message to the user about why the app is scanning in the background. The notification must include an icon that will be displayed in the top bar whenever the scanning service is running. If the BeaconService is configured to run in a different process, this call will have no effect.
-
disableForegroundServiceScanning
public void disableForegroundServiceScanning() throws IllegalStateExceptionDisables a foreground scanning service, if previously configured.- Throws:
IllegalStateException- if called after consumers are already bound to the scanning service- See Also:
In order to call this method to disable a foreground service, you must unbind from the BeaconManager. You can then rebind after this call is made.
-
getForegroundServiceNotification
public Notification getForegroundServiceNotification()
- Returns:
- The notification shown for the beacon scanning service, if so configured
- See Also:
enableForegroundServiceScanning(android.app.Notification, int)
-
getForegroundServiceNotificationId
public int getForegroundServiceNotificationId()
- Returns:
- The notification shown for the beacon scanning service, if so configured
- See Also:
enableForegroundServiceScanning(android.app.Notification, int)
-
-