Skip to main content

Android - Implementing Device Registration

In this guide we will dive deeper into how you should handle the device registration. When you launch() Notificare for the first time, the device will be registered as a non-push device.

When a successful device registration takes place, we will emit an intent. If you have configured a custom intent receiver as mentioned in the Implementation page, you can receive those intents by overriding the onDeviceRegistered() method from NotificareIntentReceiver.

class CustomIntentReceiver : NotificareIntentReceiver() {

override fun onDeviceRegistered(context: Context, device: NotificareDevice) {

}
}

You can also check the details of the currently registered device.

Notificare.device().currentDevice

The onReady() method in NotificareIntentReceiver will also be called when all Notificare modules have been launched, including a successful device registration.

Additionally, you can verify whether Notificare is ready at any point by calling Notificare.isReady or listen to the onReady event anywhere in your code by adding a Notificare.OnReadyListener as described below.

class MainActivity : AppCompatActivity(), Notificare.Listener {

override fun onCreate(savedInstanceState: Bundle?) {
// more code ...

Notificare.addListener(this)
}

override fun onDestroy() {
// more code ...

Notificare.removeListener(this)
}

// region Notificare.OnReadyListener

override fun onReady(application: NotificareApplication) {

}

override fun onUnlaunched() {

}

// endregion

}

Assign a user to the device

By default, a device is registered as an anonymous user. However, to fully use push notifications in your Actito omni-channel strategy, simply registering an anonymous device is not what you want. For example, if you authenticate your users, you will want to assign user information to the registered device as shown below.

Notificare.device().updateUser(
userId = "7f42bedc-d74b-4c64-a5cf-76bcc5130b05",
userName = "John Doe",
callback = object : NotificareCallback<Unit> {
override fun onSuccess(result: Unit) {

}

override fun onFailure(e: Exception) {

}
}
)

After that, the device will remain registered with that userId / userName until you explicitly set the user as anonymous. Depending on the way you authenticate users, you might want to check the logged-in state on launch (in the onReady) and change it if necessary. Forcing registration as anonymous can be best achieved by setting userId and userName to null.

tip

Only the userId will be used to match devices to profiles in your Actito DB.
The userName is only used to provided additional information.

Notificare.device().updateUser(
userId = null,
userName = null,
callback = object : NotificareCallback<Unit> {
override fun onSuccess(result: Unit) {

}

override fun onFailure(e: Exception) {

}
}
)

To choose the proper user ID:

  • The data must be available as a key in Actito thanks to the data synchronization between your system and Actito.
  • The data must be available on your website (through logging into a client space).

Please use an attribute which is already defined as unique on your Actito profile table.

info

If you need to add a new unique attribute, this is possible, but be careful because it could have impacts on your data synchronization process between your system and Actito. Ask your Integration Data Expert if necessary.

Override Device Language

By default, we will automatically collect the language and region of a device based on the Locale of the device. For most cases this will be enough but for those cases where you would like to override the device language and region combination to a strict selection of languages, you can do so by invoking the following method:

Notificare.device().updatePreferredLanguage("en-US", object : NotificareCallback<Unit> {
override fun onSuccess(result: Unit) {

}

override fun onFailure(e: Exception) {

}
})

Eventually, you can always retrieve the preferred language by calling the following method:

Notificare.device().preferredLanguage