SDK

Implementation

If you've completed the steps described in the Setup guides, you are now ready to implement our Android library in your app. Our library supports Android version 6 and up. Make sure you always have the latest Android SDK when using this library.

If you are upgrading from an older version of our library, it's always a good idea to read our Migration guide.

Dependencies

For your convenience we've created a Gradle Plugin that simplifies how you configure the Notificare SDK. Open the build.gradle file of your project and add the following entries:

buildscript {
    repositories {
        maven { url 'https://maven.notifica.re/releases' }
    }
    dependencies {
        classpath 're.notifica.gradle:notificare-services:1.0.0'
    }
}

allprojects {
    repositories {
        maven { url 'https://maven.notifica.re/releases' }
    }
}

In the app/build.gradle of your application, add the plugin and dependencies that you need.

plugins {
    // ...
    id 're.notifica.gradle.notificare-services'
}

dependencies {
    def notificare_version = '3.0.0-alpha.1'
    implementation "re.notifica:notificare:$notificare_version"

    // Optional modules
    implementation "re.notifica:notificare-inbox:$notificare_version"

    implementation "re.notifica:notificare-push:$notificare_version"
    implementation "re.notifica:notificare-push-fcm:$notificare_version"
    implementation "re.notifica:notificare-push-hms:$notificare_version"

    implementation "re.notifica:notificare-push-ui:$notificare_version"
    implementation "re.notifica:notificare-push-ui-fcm:$notificare_version"
    implementation "re.notifica:notificare-push-ui-hms:$notificare_version"
}

Configuration file

In order to connect your app to Notificare, you need to download the configuration file from the Dashboard and place it under app/notificare-services.json. The configuration file can be downloaded by opening your Notificare application and going into the App Keys section via Menu > Settings > App Keys.

app keys v3 download

For your reference, here's what this file should look like:

{
  "project_info": {
    "application_id": "{{ YOUR APPLICATION ID }}",
    "application_key": "{{ YOUR APPLICATION KEY }}",
    "application_secret": "{{ YOUR APPLICATION SECRET }}"
  }
}

It is recommended that you create at least two different apps in Notificare using separated environments for development and production. For each app you will have a different set of keys, resulting in two different configuration files. We recommend you to leverage Android's build variants / product flavours to manage which file will be embedded in the application.

Create an Intent Receiver

While this is an optional step, by creating your own intent receiver, you can listen to the ready and device_registered events. You can take the opportunity to perform additional steps when Notificare becomes ready or when the device is updated.

class CustomIntentReceiver : NotificareIntentReceiver() {

    override fun onReady(application: NotificareApplication) {
        // At this point you have been assigned a temporary device identifier
        // All services subscribed can be used
    }

    override fun onDeviceRegistered(device: NotificareDevice) {
        // At this point you know a device is registered with the Notificare API
        // This method will be called every time something changes, be it token, push enabled/disabled or other property changes
        // Use this method to keep track of device changes in your own app or act on those changes
    }
}
public class CustomIntentReceiver extends NotificareIntentReceiver {

    @Override
    protected void onReady(@NotNull NotificareApplication application) {
        // At this point you have been assigned a temporary device identifier
        // All services subscribed can be used
    }

    @Override
    protected void onDeviceRegistered(@NotNull NotificareDevice device) {
        // At this point you know a device is registered with the Notificare API
        // This method will be called every time something changes, be it token, push enabled/disabled or other property changes
        // Use this method to keep track of device changes in your own app or act on those changes
    }
}

To let Notificare know about your intent receiver, you can execute the following statement:

Notificare.intentReceiver = CustomIntentReceiver::class.java
Notificare.INSTANCE.setIntentReceiver(CustomIntentReceiver.class);

When creating your custom intent receiver, you also need to declare it in your Manifest.xml file.

<?xml version="1.0" encoding="utf-8"?>
<manifest>

    <application>

        <receiver
            android:name=".CustomIntentReceiver"
            android:exported="false" />

    </application>

</manifest>

Launching Notificare

Launching Notificare is as simple as calling Notificare.launch(). However, before launching, you may want to consider customising some properties.

In the core module you can enable advanced logging which is helpful to diagnose problems during the development. If you have created a custom intent receiver, you should also set the Notificare.intentReceiver property to let Notificare know which class will handle the intents.

Despite not being mandatory, a good place to launch Notificare is when the Android application is created. A small code sample can be found below.

class MainApplication : Application() {

    override fun onCreate() {
        super.onCreate()

        // Output additional logs. Useful to diagnose problems and execution flows.
        Notificare.useAdvancedLogging = BuildConfig.DEBUG

        // In case you want to setup your custom intent receiver.
        Notificare.intentReceiver = CustomIntentReceiver::class.java

        // Launch Notificare! 🚀
        Notificare.launch()
    }
}
public class CustomApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        // Output additional logs. Useful to diagnose problems and execution flows.
        Notificare.INSTANCE.setUseAdvancedLogging(BuildConfig.DEBUG);

        // In case you want to setup your custom intent receiver.
        Notificare.INSTANCE.setIntentReceiver(CustomIntentReceiver.class);

        // Launch Notificare! 🚀
        Notificare.INSTANCE.launch();
    }
}

Un-launch Notificare

Finally, it is also possible to completely remove all data for a device, both locally in your app and remotely in our servers. To do that, use the following method:

Notificare.unlaunch()
Notificare.INSTANCE.unlaunch();

After invoking this, all the device's data will be destroyed and cannot be undone. Also, invoking any other method in Notificare will fail, and the only way to start using the SDK again, is by invoking its counterpart, the launch method.