├ 05

android client

You need a Firebase project with Cloud Messaging enabled and your google-services.json file in your app's app/ directory. The same Firebase project must own the service account JSON you uploaded to edgepush.

// MyMessagingService.kt
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage

class MyMessagingService : FirebaseMessagingService() {

  override fun onNewToken(token: String) {
    sendTokenToServer(token)
  }

  override fun onMessageReceived(message: RemoteMessage) {
    // Optional: handle pushes received while the app is foregrounded.
  }
}

Register the service in AndroidManifest.xml:

<service
  android:name=".MyMessagingService"
  android:exported="false">
  <intent-filter>
    <action android:name="com.google.firebase.MESSAGING_EVENT" />
  </intent-filter>
</service>

Fetch the initial token after sign-in:

import com.google.firebase.messaging.FirebaseMessaging
import kotlinx.coroutines.tasks.await

suspend fun fetchInitialFcmToken(): String? {
  return try {
    FirebaseMessaging.getInstance().token.await()
  } catch (e: Exception) {
    null  // Google Play Services unavailable, etc.
  }
}

─  notes

  • The token is a long opaque string (over 150 characters), much longer than an APNs hex token. edgepush auto-detects format on /v1/send if you don't pass a platform field, but you can set it explicitly.
  • The Firebase project ID in your client's google-services.json must match the project_id inside the FCM service account JSON you uploaded to edgepush. Different projects = silent delivery failures.
  • If your app supports multiple flavors (e.g. dev / staging / prod) point each flavor at its own Firebase project AND its own edgepush app. Don't cross-wire credentials.