Kotlin library for sending Firebase Cloud Messages using the v1 HTTP protocol.
Sending of messages to FCM requires the admin service account credentials.
- Navigate to your project in the Firebase console
- Click the settings gear icon and then
Project settings
in the drop down - Click the
Service Accounts
tab - Click
Generate new private key
on theFirebase Admin SDK
tab
// Create the client using the downloaded google-services.json
val fcmClient = File("google-services.json")
.inputStream()
.let { accountStream -> GoogleServiceAccountResolver(accountStream) }
.let { accountResolver -> HttpUrlFcmClient(accountResolver) }
// Create a message and give it to the client for delivery to FCM
fcmClient.send(
Message(
data = mapOf(
"Hello" to "World!"
),
android = AndroidConfig(
restrictedPackageName = "com.sample.package"
),
condition = "'my-channel' in topics"
)
)
implementation "com.ToxicBakery.fcmclient:fcm-client:1.+"