0.0.3 • Published 8 years ago

background-beacon-monitoring v0.0.3

Weekly downloads
3
License
Apache 2.0
Repository
github
Last release
8 years ago

Background Beacon Monitoring

Cordova plugin allowing background beacon monitoring and ranging on Android. Uses the altbeacon library for providing the API to interact with beacons.

The altbeacon library jar is provided in libs/android directory.

Installation

Installing the plugin is as simple as adding the plugin to cordova using the plugin add command.

cordova plugin add https://github.com/nirina-apiqa/background-beacon-monitoring.git

To install the plugin when using the Ionic framework the following command will add the plugin and save it to package.json.

ionic plugin add https://github.com/nirina-apiqa/background-beacon-monitoring.git

Currently the altbeacon jar file is not linked when the plugin is installed due to a clash if the cordova-plugin-ibeacon is installed as this also uses the altbeacon library for Android (currently working on fixing this). If this is only being used then uncomment the following line in plugin.xml, fix for this is being worked on.

<!-- <source-file src="libs/android/altbeacon.jar" target-dir="libs" framework="true" /> -->

Usage

Once the plugin is added it is available for use as BackgroundBeaconMonitoring

In order to access the location information and details of the beacons detected the plugin requires either of ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION. The app requests both of these permissions from the user through the BackgroundBeaconMonitoring.requestPermissions() method.

After the user has given permission to access their location information the service can be started using the BackgroundBeaconMonitoring.startService() method.

API Reference

requestPermissions()

BackgroundBeaconMonitoring.requestPermissions(successCallback, errorCallback)

Requests the permissions needed to access the users location and therefore the beacon information. The success and error callbacks are optional.

ParameterDescription
successCallbackOptional Callback function to run when the method returns successfully
errorCallbackOptional Callback function to run when the method returns an error, the function can accept a parameter to hold the message returned from the native layer so any errors encountered eg. 'PERMISSION DENIED' can be dealt with in the calling application appropriately

startService()

BackgroundBeaconMonitoring.startService(device_id, monitoring_api_url, ranging_api_url, sendMovementData, successCallback, errorCallback)

Starts the background service and sets the location and access details for the API.

ParameterDescription
device_idThe device id of the user mobile device. For consistency with requests sent within the app this is generated using $cordovaDevice.getUUID() in ionic/cordova
monitoring_api_urlThe URL fetched after background entering or exiting region event`
ranging_api_urlThe URL fetched after background ranging event
sendMovementDataWhether to actually send the interactions with the beacons or not
successCallbackCallback function to run when the method returns successfully
errorCallbackCallback function to run when the method returns an error

startMonitoringRegion()

BackgroundBeaconMonitoring.startMonitoringRegion(identifier, uuid, major, minor, successCallback, errorCallback)

Starts monitoring the region specified by the uuid, major and minor and labels it with the unique identifier.

ParameterDescription
identifierThe unique identifier/name of the region to start monitoring
uuidThe uuid of the region to monitor
majorThe major id number of the region to monitor - can be null so monitors all beacons for the uuid
minorThe minor id number of the region to monitor - can be null and will scan for all beacons with uuid and major if major is specified, If major is null then this value is ignored
successCallbackCallback function to run when the method returns successfully
errorCallbackcallback function to run when the method returns an error

stopMonitoringRegion()

BackgroundBeaconMonitoring.stopMonitoringRegion(identifier, successCallback, errorCallback)

Stop monitoring the region specified by identifier, this is the same unique identifier used in the startMonitoringRegion() method.

ParameterDescription
identifierThe unique identifier/name of the region to stop monitoring, this is the same one as used to start monitoring
successCallbackCallback function to run when the method returns successfully
errorCallbackCallback function to run when the method returns an error

startRangingRegion()

BackgroundBeaconMonitoring.startRangingRegion(identifier, uuid, major, minor, successCallback, errorCallback)

Starts ranging the region specified by the uuid, major and minor and labels it with the unique identifier. The unique identifier can be the same as one used with associated uuid/major/minor in startMonitoringRegion() to range the region as well.

ParameterDescription
identifierThe unique identifier/name of the region to start ranging
uuidThe uuid of the region to range
majorThe major id number of the region to range - can be null so monitors all beacons for the uuid
minorThe minor id number of the region to range - can be null and will scan for all beacons with uuid and major if major is specified, If major is null then this value is ignored
successCallbackCallback function to run when the method returns successfully
errorCallbackcallback function to run when the method returns an error

stopRangingRegion()

BackgroundBeaconMonitoring.stopRangingRegion(identifier, successCallback, errorCallback)

Stop ranging the region specified by identifier, this is the same unique identifier used in the startRangingRegion() method.

ParameterDescription
identifierThe unique identifier/name of the region to stop ranging, this is the same one as used to start monitoring
successCallbackCallback function to run when the method returns successfully
errorCallbackCallback function to run when the method returns an error

setMovementPreference()

BackgroundBeaconMonitoring.setMovementPreference(preference, successCallback, errorCallback)

Changes the movement preference which controls whether the service sends interactions with the beacons, allows the user of the application to control the privacy of their movements.

ParameterDescription
preferenceTrue/False Boolean Parameter to change whether the service sends to the API
successCallbackCallback function to run when the method returns successfully
errorCallbackCallback function to run when the method returns an error

Contributors

Contributions welcome by pull request.

License

Apache License v2.0