Setup¶
Firebase¶
- Create a Firebase project, register your Android app in it and download
google-services.jsoninto your app module. - Apply the Google services Gradle plugin,
com.google.gms.google-services, to the app module.
Without Firebase set up, the SDK still runs, but never gets a push token.
Start the SDK¶
Start the SDK in your Application's onCreate, so it also runs when a push starts the app's process:
Kotlin
class App : Application() {
override fun onCreate() {
super.onCreate()
PlingBuddy.initialize(this, Configuration(applicationId = "<your application id>"))
}
}
initializeonly does something in the app's main process; in any other process it's ignored.- When the app knows its user at launch, pass it as well, so the first request already names the user:
initialize(this, configuration, externalId = "user-42"). See Users and data. initializecan be called again. Each call replaces the whole configuration, so pass every setting again,baseUrlincluded: a configuration without it goes to production, which starts a new installation there.
Configuration¶
| Parameter | Default | |
|---|---|---|
applicationId |
Your application's id, from its settings page in the dashboard (Getting started). | |
baseUrl |
production | PlingBuddy.STAGING_URL for staging. |
showNotificationsInForeground |
null: shown |
Whether the service's notifications show while the app is open. See Notifications. |
fetchLocaleAndTimezone |
false |
Fill in the user's country, language and time zone from the device. See Users and data. |
identityTokenProvider |
null |
For applications with identity verification. |
For staging:
Kotlin
PlingBuddy.initialize(this, Configuration(
applicationId = "<your staging application id>",
baseUrl = PlingBuddy.STAGING_URL,
))
Ask for permission¶
Ask when the app wants to offer notifications:
Kotlin
lifecycleScope.launch {
val allowed = PlingBuddy.askForPermission()
}
- It shows the system prompt while Android still allows it, and once it doesn't (the user denied it), a dialog offering the app's notification settings. It answers whether notifications are allowed afterwards.
- Change the dialog's texts with a
SettingsPrompt:
Kotlin
val allowed = PlingBuddy.askForPermission(SettingsPrompt(
title = "Notifications are off",
message = "Open Settings to turn them on.",
openButton = "Open Settings",
cancelButton = "Not now",
))
- Java and other callers without coroutines use the overloads with a callback, here and for
deleteRecipientandpushToken.
On Android 13+, the system prompt only appears for apps that target API 33 or higher. For apps that target lower, Android shows its own prompt when the app creates its first notification channel; askForPermission then shows the Settings dialog instead.
PlingBuddy.permissionStatus() reads the permission without prompting: GRANTED, DENIED or NOT_DETERMINED. PlingBuddy.pushToken() answers the FCM token while notifications are allowed, and otherwise null.