Android
Integrate the Msgera Android SDK with Firebase Cloud Messaging.
The Msgera Android SDK delivers notifications through Firebase Cloud Messaging (FCM HTTP v1) using your own Firebase service account key.
1. Upload your Firebase service account JSON
In the Firebase Console, open Project settings → Service accounts and click Generate new private key. Paste the downloaded JSON into your Push App's Platforms → Android card in the Msgera dashboard. Also place google-services.json in your Android app's app/ module.
2. Add the Gradle dependency
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven("https://jitpack.io")
}
}3. Initialize the SDK
Call MsgeraPush.init(context, appId) inside your Application.onCreate(). Initialization never prompts the user for permission; if permission was already granted, it refreshes the device token automatically.
import android.app.Application
import io.msgera.push.MsgeraPush
class MainApplication : Application() {
override fun onCreate() {
super.onCreate()
MsgeraPush.init(this, "YOUR_PUBLIC_ID")
}
}4. Request notification permission
On Android 13+ (API 33), apps must request POST_NOTIFICATIONS at runtime. The SDK includes a transparent MsgeraPermissionActivity so you can call requestPermission from anywhere without forwarding onRequestPermissionsResult:
// Ask for permission; if previously denied, fallbackToSettings opens App Notification Settings
MsgeraPush.requestPermission(fallbackToSettings = true) { granted ->
if (granted) {
// Subscribed and ready to receive notifications
}
}
// Link the device to your authenticated user
MsgeraPush.login("user_123", userHash = hmacFromBackend)
// Unlink on sign-out
MsgeraPush.logout()
// Enable verbose logging while debugging
MsgeraPush.setLogLevel(MsgeraPush.LogLevel.VERBOSE)Small notification icon (ic_stat_msgera)
res/drawable/ic_stat_msgera.xml in your app—the SDK uses it automatically and falls back to your launcher icon if absent.Sounds and channels
res/raw/ (up to 30 seconds, .wav, .mp3, or .ogg). Use the file name without the extension as the channel sound in the dashboard. The app registers key_vVersion. Changing the sound or importance bumps the version, because Android cannot update those on an existing channel.