Skip to content

Push Notifications

Push notifications allow an app that isnโ€™t running in the foreground to notify the user when it has information for them. Push notifications originate from a notification server and are pushed to your app on a userโ€™s device.

Setup Push Notifications

By default, Numberly handles the FirebaseMessagingService implementation that receives the notifications and forward them to the notification center.

The Push module offers some great helpers and callbacks, you just need to set it's callback which implements the NLPushCallback protocol

class MyApplication : Application(), NLPushCallback {
    override fun onCreate() {
        super.onCreate()
        [...] // Don't forget to initialize the SDK first
        Numberly.setPushActionCallback(this)
    }

    override fun pushOpenedWithData(data: JSONObject) {
        // TODO implement logic for the extra data received by the opened notification
        NLLog.debug(TAG, data.toString())
    }
}
public class MyApplication extends Application implements NLPushCallback {
    @Override
    public void onCreate() {
        super.onCreate();
        [...] // Don't forget to initialize the SDK first
        Numberly.setPushActionCallback(this);
    }

    @Override
    public void pushOpenedWithData(JSONObject data) {
        // TODO implement logic for the extra data received by the opened notification
        NLLog.debug(TAG, data.toString());
    }
}

Retrieving the current token

You can retrieve the current Firebase token anywhere inside your app

Numberly.getPushToken(applicationContext, object : NLTokenCallback {
    override fun onTokenReceived(token: String) {
        // Do something amazing with your token !
        NLLog.debug(TAG, "Token: $token")
    }
})
Numberly.getPushToken(new NLTokenCallback() {
    @Override
    void onTokenReceived(String token) {
        // Do something amazing with your token !
        NLLog.debug(TAG, "Token: " + token)
    }
})