On Android, the wake-up mechanism is slightly different from iOS as there is no similarly efficient way to register to iBeacon identifiers. Instead, we rely on Android OS Location (information provided by the Android API from a combination of GPS/GSM data). The idea is to define a circular area covering the site of interest which is then registered with Android OS Location. That area is defined on NAOCloud (Site and maps/ Site location) and is represented by a red circle (screenshot below).
The following information will need to declare two extra services in AndroidManifest.xml
.
The purpose of those two services is to catch geofence GPS Enter/Exit events and to notify your app upon entering the area where beacons are deployed.
<service
android:name="com.polestar.naosdk.controllers.AndroidGeofencingService"
android:exported="true"
android:label="@string/app_name"
/>
<service android:name="com.polestar.models.GeofenceTransition" android:exported="true" android:label="@string/app_name" android:process=":geofencing" />
Important: On Android 10, background restrictions continue evoluated (cf. https://docs.nao-cloud.com/docs/misc/android-q-update/). To register your class, you need to have permission ACCESS_BACKGROUND_LOCATION granted.
Note: Since Android 8.0, in order to do Background work, you need to use Foreground services. (cf. https://docs.nao-cloud.com/docs/misc/android-8-update/)
Hence, we have created a surchargeable method called wakeUpNotification() that provides us the notification to display during wakeUp execution.
/**
* Method called to set the notification of the wakeUpController
* which will be used for wakeUp feature when listening for signals
* @return the notification that will be displayed
*/
public Notification wakeUpNotification() {
//return an default Notification
...
return notification;
}
NAOServicesConfig.enableOnSiteWakeUp(context, api_key, OnSiteWakeUpNotifier.class, new NAOWakeUpRegistrationListener() {
@Override
public void onStatusChanged(TNAOWAKEUP_REGISTER_STATUS status, String message) {
//Receive registration status here
}
});
Note: NAOWakeUpRegistrationListener is optionnal
Important: To register your class, you need to have everything synchronized for the API key used (i.e.: NAO SDK data) and permission ACCESS_FINE_LOCATION granted.
NAOServicesConfig.disableOnSiteWakeUp(context, api_key, new NAOWakeUpRegistrationListener() {
@Override
public void onStatusChanged(TNAOWAKEUP_REGISTER_STATUS status, String message) {
//Receive registration status here
}
});
When rebooting the device or turning off and back on the Android Location Provider, geofences are de-registered which disables the wake-up behavior.
a. To ensure the wake-up persistence across those two events, you will need to declare one BroadcastReceiver:
<receiver
android:name="com.polestar.models.RegisterGeofenceGPSReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
android:enabled="true">
<intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
b. You will also need to add a specific permission to enable RegisterGeofenceGPSReceiver in AndroidManifest.xml
:
<!-- optional - needed to start the service on boot for on-site wake-up -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />