SDK

Location Services

In this page you'll dive deeper into functionality like using GPS signals to get the user's location or monitor their visits to regions and proximity to BTLE devices. These services will bring a new level of contextuality to your app, allowing you to create geo-triggers to send notifications or categorize users based on their location behaviour.

If you are going to use location services, you must include the notificare-location dependency in your /app/build.gradle:

dependencies {
    ...more
    implementation "re.notifica:notificare-location:2.2.0"
}

Requesting Permission

Additionally to these manifest permissions, since Android 6 (a.k.a Marshmallow), applications will need to request the user permission to use location. These permissions need to be requested in your app, after which you can safely enable location updates. To make sure the location updates aren't started before the library is ready to be used or a device has been registered, as shown below:

Notificare.on('ready', function(data) {

    Notificare.startLocationUpdates();

});
Notificare.on('ready', async (data) => {

    await Notificare.startLocationUpdates();

});

Once you have implemented the code above, if permission is granted, our library will automatically collect the user location and start monitoring for regions you've created via the dashboard or API.

Using Bluetooth Low-Energy beacons

Once you've implemented GPS location in your app, you can also listen to Bluetooth signals from BTLE beacons in your app. This will require you to also include the notificare-beacon dependency in your app. Simply add the following to your /android/app/build.gradle file:

dependencies {
    ...more
    implementation "re.notifica:notificare-beacon:2.2.0"
}

After that you can enable beacons signals by simply invoking the following method, right after a user has granted permission for tracking location:

Notificare.on('ready', function(data) {

    Notificare.startLocationUpdates();
    Notificare.enableBeacons();

});
Notificare.on('ready', async (data) => {

    await Notificare.startLocationUpdates();
    await Notificare.enableBeacons();

});

By doing this, your app will start monitoring for any beacons you inserted via the dashboard or API, in any of your regions.

Disable Location

Pretty much the same you enable location, you can also stop tracking the user location by invoking the following method:

Notificare.stopLocationUpdates();
await Notificare.stopLocationUpdates();

Disable Beacons

Although beacons will not work without using location, you can also stop listening to beacon advertising signals by invoking the following method:

Notificare.disableBeacons();
await Notificare.disableBeacons();