Class CefriumPush

java.lang.Object
com.cefrium.CefriumPush

public final class CefriumPush extends Object
Delivers Web Push messages to the engine.

A page's PushManager.subscribe() registers with Firebase Cloud Messaging, and FCM delivers each message to the app's FirebaseMessagingService. An app that already has one passes every message through handleMessage(Context, String, Bundle); the ones that belong to a web page go to the engine, which wakes that page's service worker in the profile that subscribed, and the rest stay with the app:

public void onMessageReceived(RemoteMessage message) {
    if (CefriumPush.handleMessage(this, message.getFrom(),
            message.toIntent().getExtras())) {
        return;  // A Web Push message, delivered to the page.
    }
    // The app's own message.
}

An app without its own Firebase service enables CefriumPushService instead, which does the above. An app that uses another push service installs a CefriumPushTransport with setTransport(CefriumPushTransport). Messages that a CefriumRelayTransport relay sends through the app's Firebase project arrive the same way and are handled here too.

  • Method Details

    • isWebPushMessage

      public static boolean isWebPushMessage(android.os.Bundle data)
      Returns:
      true if data is a Web Push message for the engine.
    • handleMessage

      public static boolean handleMessage(android.content.Context context, String from, android.os.Bundle data)
      Hands a Web Push message to the engine.
      Parameters:
      context - any context of the app.
      from - the message's sender, RemoteMessage.getFrom().
      data - the message's extras, RemoteMessage.toIntent().getExtras().
      Returns:
      true if it was a Web Push message, now on its way to the page; false if it belongs to the app.
    • setTransport

      public static void setTransport(CefriumPushTransport transport)
      Serves every Web Push subscription made from now on with transport instead of Firebase Cloud Messaging; null restores FCM. Call it in Application.onCreate(), so the transport is in place when a message or an unsubscribe arrives after a restart. Subscriptions made before keep the service they were made with.
    • deliverMessage

      public static boolean deliverMessage(android.content.Context context, String appId, byte[] body)
      Hands a message that a CefriumPushTransport received to the engine.
      Parameters:
      appId - the subscription, as passed to CefriumPushTransport.subscribe(String, String).
      body - the request body the application server sent: an RFC 8291 aes128gcm message, still encrypted.
      Returns:
      false if appId is not a subscription the transport made.