Android SDK Setup
Integrate Push Notifications into your native Android app to receive and handle push notifications via Firebase Cloud Messaging (FCM).
v1.0.6-beta. Not for production use. Pin the exact version. APIs may change without notice.
- Make sure to configure the App ID properly. For additional information see Getting started
- Configure your push credentials in the AppsOnAir console under App Settings → Push Notifications — upload your Firebase service account JSON (Android) before sending any notifications.
Requirements
Make sure your project meets the following minimum requirements before integrating the SDK.
| Minimum | |
|---|---|
| Android | API 24 (Android 7.0) |
| Kotlin | 1.8+ |
| JVM target | 17 |
| Firebase | google-services.json required |
Basic push — Steps 1–5 only. No extension targets needed on Android:
- Text notifications with title and body
- Tap-to-open and deep links
- Images (download automatically via the data payload — no extra setup)
- Foreground display control
- User targeting, tags, segments, opt-in / opt-out
Advanced features — all handled by the SDK, no separate targets required:
| Feature | How |
|---|---|
| Images | Include big_picture in the FCM data payload |
| Notification channels | Use the Channel API in Feature Guides (Android 8.0+) |
| Silent push | Register setSilentPushListener() and send "silent": "true" in a data-only payload. See Silent Push |
| Badge count | Use setBadgeCount() in Feature Guides |
Unlike iOS, Android has no extension targets. All configuration is done in the SDK itself.
Step 1: Firebase Setup
Push Notifications uses Firebase Cloud Messaging (FCM) to deliver notifications on Android. You need to connect your app to a Firebase project before the SDK can function.
- Open the Firebase Console and create (or select) your Android app.
- Download
google-services.jsonand place it in yourapp/folder.
Step 2: Add the SDK Dependency
Add the JitPack repository and the Push Notifications dependency to your Gradle files.
- Kotlin DSL (.kts)
- Groovy DSL
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven("https://jitpack.io")
}
}
plugins {
id("com.google.gms.google-services") version "4.4.2" apply false
}
plugins {
id("com.google.gms.google-services")
}
android {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions { jvmTarget = "17" }
}
dependencies {
implementation("com.github.apps-on-air:appsonair-android-push-notification:1.0.6-beta")
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
plugins {
id 'com.google.gms.google-services' version '4.4.2' apply false
}
plugins {
id 'com.google.gms.google-services'
}
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}
dependencies {
implementation 'com.github.apps-on-air:appsonair-android-push-notification:1.0.6-beta'
}
After editing your Gradle files, press Sync Now on the banner that appears in Android Studio to download the SDK.
Step 3: Notification Icon & Color
Android draws the status-bar (small) icon from its alpha channel only. Every non-transparent pixel is painted one solid colour. If you skip this step, the SDK uses your launcher icon, which shows up as a white square, and logs a WARN once.
3.1 Icon requirements
| Requirement | |
|---|---|
| Style | Monochrome white silhouette on a transparent background. No gradients, shadows or solid backgrounds. |
| Resource type | A drawable (res/drawable or res/drawable-<density>). Not mipmap. |
| Name | Any valid resource name. We recommend ic_stat_appsonair_default. |
| Format | A vector drawable (one file) or PNGs for each density below. |
PNG sizes (24 dp icon):
| Folder | Size |
|---|---|
drawable-mdpi | 24 × 24 px |
drawable-hdpi | 36 × 36 px |
drawable-xhdpi | 48 × 48 px |
drawable-xxhdpi | 72 × 72 px |
drawable-xxxhdpi | 96 × 96 px |
Use Android Studio's File → New → Image Asset → Icon type: Notification Icons, or Android Asset Studio. Both produce every density from one image.
3.2 Add the icon and color resources
Vector drawable (minSdk 24 supports vectors natively, so one file covers every density):
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#FFFFFF">
<!-- Replace pathData with your own silhouette -->
<path
android:fillColor="#FFFFFF"
android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.9,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z" />
</vector>
Accent color. It must be a color resource; a raw hex value in the manifest isn't read:
<resources>
<color name="appsonair_notification_accent_color">#2E6BE6</color>
</resources>
3.3 Declare them in AndroidManifest.xml
Add both pairs inside <application>, pointing at the same resources. The first pair is read by the SDK. The second pair is read by Firebase when it draws a notification-block message itself while the app is in the background.
<application ...>
<!-- AppsOnAir SDK: notifications the SDK renders (data-only, or any push while in foreground) -->
<meta-data
android:name="com.appsonair.apppush.default_notification_icon"
android:resource="@drawable/ic_stat_appsonair_default" />
<meta-data
android:name="com.appsonair.apppush.default_notification_color"
android:resource="@color/appsonair_notification_accent_color" />
<!-- Firebase: notification-block messages Firebase renders while the app is in background -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_stat_appsonair_default" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/appsonair_notification_accent_color" />
</application>
3.4 How the SDK picks the icon and color
For notifications the SDK renders:
| Order of precedence | |
|---|---|
| Small icon | small_icon data key (drawable name) → com.appsonair.apppush.default_notification_icon → launcher icon (white square + WARN log) |
| Accent color | bg_color data key (hex, e.g. "#2E6BE6" or "FF2E6BE6") → com.appsonair.apppush.default_notification_color → none |
| Large icon (thumbnail) | large_icon data key (HTTPS URL or drawable name) → image_url data key → none. There is no app-level default. |
small_icon and a drawable-name large_icon are looked up in res/drawable by name. If the name isn't found, the SDK logs a WARN and falls back to the next option. Downloaded large icons are scaled down to fit 256 × 256 px.
small_icon, large_icon and bg_color are read from the raw FCM data payload. The Send Push API doesn't have dedicated fields for them, so the manifest defaults above are the supported way to set your icon.
3.5 Differences from OneSignal
If you're migrating from OneSignal, note these differences:
| OneSignal | AppsOnAir | |
|---|---|---|
| Default small icon | Picked up automatically if named ic_stat_onesignal_default | Must be declared with the com.appsonair.apppush.default_notification_icon meta-data. The file name alone does nothing. |
| Default large icon | ic_onesignal_large_icon_default resource | Not supported. Use the large_icon payload key per notification. |
| Accent color | onesignal_notification_accent_color string, or com.onesignal.NotificationAccentColor.DEFAULT meta-data (ARGB) | com.appsonair.apppush.default_notification_color meta-data pointing at a @color resource |
| Per-notification override | small_icon, large_icon, android_accent_color API fields | small_icon, large_icon, bg_color FCM data keys (not in the Send Push API) |
| iOS icon | App icon only | App icon only (same) |
Step 4: Initialize the SDK
Initialize AppPushService inside your custom Application class so it starts as early as possible in the app lifecycle. This registers the device with FCM and prepares the SDK to receive notifications.
- Kotlin
- Java
import android.app.Application
import com.appsonair.apppush.AppPushService
import com.appsonair.apppush.LogLevel
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
// Optional: enable verbose logging before initialize (dev builds only)
AppPushService.Debug.logLevel = LogLevel.VERBOSE
AppPushService.initialize(this)
}
}
import android.app.Application;
import com.appsonair.apppush.AppPushService;
import com.appsonair.apppush.LogLevel;
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
// Optional: enable verbose logging before initialize (dev builds only)
AppPushService.Debug.setLogLevel(LogLevel.VERBOSE);
AppPushService.initialize(this);
}
}
Make sure MyApp is registered in AndroidManifest.xml:
<application
android:name=".MyApp"
...>
Step 5: Wire Your Activity
Implement PushListener in your main Activity to receive notification events and handle taps. The SDK calls these callbacks when a notification arrives, is opened, or when an error occurs.
- Kotlin
- Java
import com.appsonair.apppush.AppPushService
import com.appsonair.apppush.PushListener
import com.appsonair.apppush.PushNotification
import com.appsonair.apppush.PushError
class MainActivity : AppCompatActivity(), PushListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
AppPushService.setListener(this)
AppPushService.requestNotificationPermission(this)
AppPushService.handleNotificationTapIntent(intent) // cold-start taps
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
intent?.let { AppPushService.handleNotificationTapIntent(it) }
}
override fun onDestroy() {
super.onDestroy()
AppPushService.setListener(null)
}
override fun onTokenUpdated(token: String) {
// FCM token refreshed
}
override fun onNotificationReceived(notification: PushNotification) {
// Notification received while app is in foreground
}
override fun onNotificationOpened(notification: PushNotification) {
// User tapped the notification
}
override fun onError(error: PushError) {
// Handle SDK error
}
}
import com.appsonair.apppush.AppPushService;
import com.appsonair.apppush.PushListener;
import com.appsonair.apppush.PushNotification;
import com.appsonair.apppush.PushError;
public class MainActivity extends AppCompatActivity implements PushListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AppPushService.setListener(this);
AppPushService.requestNotificationPermission(this);
AppPushService.handleNotificationTapIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent != null) {
AppPushService.handleNotificationTapIntent(intent);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
AppPushService.setListener(null);
}
@Override
public void onTokenUpdated(String token) { }
@Override
public void onNotificationReceived(PushNotification notification) { }
@Override
public void onNotificationOpened(PushNotification notification) { }
@Override
public void onError(PushError error) { }
}
Feature Guides
Observers
Observe subscription state changes (token issued/refreshed, opt-in changed) without polling. Register after initialize().
- Kotlin
- Java
AppPushService.User.pushSubscription.addObserver(object : IPushSubscriptionObserver {
override fun onPushSubscriptionDidChange(state: PushSubscriptionChangedState) {
println("optedIn: ${state.current.optedIn}")
println("token: ${state.current.token}")
}
})
AppPushService.User.getPushSubscription().addObserver(state -> {
System.out.println("optedIn: " + state.getCurrent().isOptedIn());
System.out.println("token: " + state.getCurrent().getToken());
});
For notification callbacks (received, opened, token updated, error), implement PushListener in your Activity — see Step 5.
Permission
Request and observe the notification permission at runtime.
- Kotlin
val granted = AppPushService.Notifications.permission(context)
val canRequest = AppPushService.Notifications.canRequestPermission(context)
// Show the system dialog
AppPushService.Notifications.requestPermission(activity)
// Permanently denied on Android 13+? Open Settings instead:
AppPushService.Notifications.requestPermission(activity, fallbackToSettings = true)
// Observe changes
AppPushService.Notifications.addPermissionObserver(object : INotificationPermissionObserver {
override fun onNotificationPermissionDidChange(permission: Boolean) { }
})
User Identity
Associate a known user ID with the device after login so you can target push notifications to specific users from the portal. Call logout() when the user signs out to disassociate the device.
- Kotlin
- Java
// Associate a known user ID with this device
AppPushService.login("user_12345")
// Disassociate on sign-out (also clears tags and aliases)
AppPushService.logout()
AppPushService.login("user_12345");
AppPushService.logout();
Tags & Segmentation
Tags are key-value pairs you attach to a device to enable audience segmentation. Use them to group users by plan type, region, preferences, or any custom attribute, then target those groups from the portal.
- Kotlin
- Java
AppPushService.User.addTag("plan", "premium")
AppPushService.User.addTags(mapOf("plan" to "premium", "region" to "us-east"))
AppPushService.User.removeTag("plan")
AppPushService.User.removeTags(listOf("plan", "trial_expiry"))
AppPushService.User.getTags { tags ->
// tags fetched from backend, cache updated, callback on main thread
}
AppPushService.User.addTag("plan", "premium");
Map<String, String> tags = new HashMap<>();
tags.put("plan", "premium");
AppPushService.User.addTags(tags);
AppPushService.User.removeTag("plan");
AppPushService.User.getTags(result -> { /* callback */ });
Language
Override the device locale so the backend sends notifications already translated in the user's preferred language. Uses ISO 639-1 codes.
- Kotlin
- Java
AppPushService.User.setLanguage("fr") // ISO 639-1 code: "en", "fr", "hi", "en-US"
val current = AppPushService.User.language
AppPushService.User.setLanguage("fr");
String current = AppPushService.User.getLanguage();
Aliases & Email
Map the device to IDs in external systems (CRM, helpdesk, analytics) and associate an email address. Each subscription keeps one email, so calling addEmail again replaces the previous address.
- Kotlin
- Java
AppPushService.User.addAlias("crm_id", "CRM-9876")
AppPushService.User.addAliases(mapOf("crm_id" to "CRM-9876"))
AppPushService.User.removeAlias("crm_id")
AppPushService.User.addEmail("[email protected]")
AppPushService.User.removeEmail("[email protected]")
AppPushService.User.addAlias("crm_id", "CRM-9876");
AppPushService.User.removeAlias("crm_id");
AppPushService.User.addEmail("[email protected]");
AppPushService.User.removeEmail("[email protected]");
Opt-in / Opt-out
Let users stop receiving push notifications without revoking the OS-level permission. This is useful for in-app notification preference settings.
- Kotlin
- Java
// Stop delivery (preserves OS permission)
AppPushService.User.pushSubscription.optOut()
// Resume delivery
AppPushService.User.pushSubscription.optIn()
// Check current state (local cache, synchronous)
val optedIn = AppPushService.User.pushSubscription.optedIn
// Fetch server's copy
AppPushService.User.pushSubscription.getOptedIn { optedIn ->
// main thread; cache and observers already updated
}
AppPushService.User.getPushSubscription().optOut();
AppPushService.User.getPushSubscription().optIn();
Foreground Display
Control whether notifications show as a system banner while the app is in the foreground.
- Kotlin
AppPushService.Notifications.addForegroundLifecycleListener(object : INotificationLifecycleListener {
override fun onWillDisplay(event: NotificationWillDisplayEvent) {
// Do nothing → the SDK displays it.
// Call preventDefault() → suppressed entirely.
event.preventDefault()
}
})
Handling Taps
Listen for notification body taps and action button clicks.
- Kotlin
AppPushService.Notifications.addClickListener(object : INotificationClickListener {
override fun onClick(event: NotificationClickEvent) {
val actionId = event.result.actionId // null = body tap, else action button ID
val url = event.result.url // payload "url" key, if any
}
})
When the app is killed, Android relaunches it with an Intent carrying the notification data. Always call handleNotificationTapIntent in both onCreate and onNewIntent.
Notification Channels (Optional — Android 8.0+)
Separate channels let users control notification types independently in Settings (Android 8.0+).
- Kotlin
AppPushService.Notifications.createNotificationChannel(
context = applicationContext,
id = "transactional",
name = "Transactional Notifications",
importance = NotificationManager.IMPORTANCE_HIGH,
description = "Order updates and alerts"
)
AppPushService.Notifications.deleteNotificationChannel(context, "transactional")
A channel's sound is fixed at creation. To change it, use a new channel ID or reinstall the app.
Dismissing Notifications
- Kotlin
AppPushService.Notifications.clearAllNotifications(context)
AppPushService.Notifications.removeNotification(context, "order-4821") // by payload notification_id
AppPushService.Notifications.removeGroupedNotifications(context, groupKey = "orders")
Badge Count (Optional)
Manually control the notification badge count on supported launchers.
- Kotlin
- Java
AppPushService.setBadgeCount(context, 5)
AppPushService.clearBadgeCount(context) // same as setBadgeCount(context, 0)
AppPushService.setBadgeCount(context, 5);
AppPushService.clearBadgeCount(context);
Badge count targets Samsung, Huawei, Xiaomi, Sony, and ASUS launchers.
Silent Push (Optional)
A silent push delivers data to your app without showing a notification. Use it to trigger a background sync, refresh content, or update local state.
The SDK treats a push as silent when its data payload contains "silent": "true". Nothing is displayed and no badge is changed. The data is passed to your silent push listener, and the push still counts as delivered in analytics.
Register the listener in Application.onCreate(). A silent push can wake a killed app before any Activity exists, so a listener registered in an Activity would miss it.
- Kotlin
- Java
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
AppPushService.setSilentPushListener { data ->
// Runs on a background thread: switch to the main thread before touching UI.
Log.d("MyApp", "Silent push received: $data")
}
AppPushService.initialize(this)
}
}
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
AppPushService.setSilentPushListener(data -> {
// Runs on a background thread: switch to the main thread before touching UI.
Log.d("MyApp", "Silent push received: " + data);
});
AppPushService.initialize(this);
}
}
{
"message": {
"token": "device-fcm-token",
"data": {
"notification_id": "notif-sync-001",
"silent": "true",
"sync_type": "orders"
}
}
}
To send a silent push from your backend, see REST API → Silent Notifications.
- The payload must be data-only. If a
notificationblock is present, Firebase shows the notification itself and the listener never fires. - Only the exact string
"true"counts."1"or"TRUE"is shown as a normal notification. - Finish within about 10 seconds or hand the work to WorkManager. FCM keeps the process alive only briefly.
- Pass
setSilentPushListener(null)to remove the listener. - Android may delay or drop silent pushes under Doze, App Standby, or battery restrictions. See When Notifications Won't Be Delivered.
Rich Media (Optional — Images & Thumbnails)
Include big_picture in a data-only FCM payload to show an expanded picture with BigPictureStyle. large_icon sets the thumbnail on the collapsed notification and works independently of big_picture. The legacy image_url key fills whichever of the two is missing. If no image loads, the SDK falls back to BigTextStyle.
{
"message": {
"token": "device-fcm-token",
"data": {
"notification_id": "notif-123",
"title": "New offer",
"body": "Limited time deal — tap to view",
"big_picture": "https://cdn.example.com/offer.jpg",
"large_icon": "https://cdn.example.com/brand-thumb.png"
}
}
}
JPEG, PNG, WebP and SVG URLs are supported, and large_icon also accepts a drawable name, including vector drawables. Images must return HTTP 2xx within the timeouts (5 s connect, 10 s read) and be no larger than 10 MB. Big pictures are scaled down to fit 1024 × 1024 px. SVGs and vectors are rendered at full size (1024 px for big_picture, 256 px for large_icon), so they stay sharp.
Payload Reference
Minimum Payload
{
"message": {
"token": "device-fcm-token",
"notification": { "title": "Hello", "body": "Push is working!" },
"data": { "notification_id": "notif-abc-123" }
}
}
Data Keys
| Key | Meaning |
|---|---|
notification_id | Unique ID surfaced as PushNotification.id. Required to dismiss the notification later. |
title / body | Pre-translated text. Falls back to the notification block if absent. |
big_picture | HTTPS image (JPEG, PNG, WebP or SVG) shown expanded with BigPictureStyle. |
large_icon | HTTPS image (JPEG, PNG, WebP or SVG) or drawable name (bitmap or vector) for the collapsed thumbnail. |
image_url | Legacy key. Used for big_picture and/or large_icon when those are absent. |
small_icon | Drawable name in res/drawable for the status-bar icon. Overrides the manifest default. |
bg_color | Hex accent color ("#2E6BE6" or "FF2E6BE6"). Overrides the manifest default. |
channel_id | Target channel. Defaults to appsonair_push_channel. |
collapse_key | A newer notification with the same key replaces the previous one instead of stacking. |
sound | File in res/raw without extension ("chime" → res/raw/chime.wav). |
actions | Up to 3 buttons: "[{\"id\":\"reply\",\"title\":\"Reply\"}]". Fires the click listener with result.actionId set. |
silent | "true" makes the push silent: nothing is displayed and the data goes to the silent push listener. Only the exact string "true" counts. |
Prefer data-only payloads (no notification block) whenever you want the SDK to control display. They guarantee onMessageReceived fires in every app state.
When Notifications Won't Be Delivered
Push delivery depends on the OS, device manufacturer, and user settings — not just your code. The following conditions can silently block or delay delivery regardless of correct SDK integration.
| Condition | Affects | Effect |
|---|---|---|
| Doze mode | Silent & visible | Android 6+ enters Doze when the device is stationary, unplugged, and the screen is off. All background network access is suspended. FCM high-priority messages can break through Doze; normal-priority and silent pushes are deferred until the next maintenance window. |
| App Standby buckets | Silent & visible | Android 9+ places apps the user hasn't interacted with recently into standby buckets. Background processing for rarely-used apps is progressively restricted — silent pushes may be deferred or dropped entirely. |
| Battery optimization enabled | Silent | If battery optimization is enabled for the app (Settings → Apps → [Your App] → Battery → Optimized), Android may delay or skip background wake-ups. Ask users to set it to Unrestricted for reliable silent push delivery. |
| Background data restricted | Silent | If the user disables background data for the app (Settings → Apps → [Your App] → Mobile data → Background data), FCM cannot deliver messages while the app is in the background on mobile data. |
| Force-stopped by user | Silent & visible | If the user force-stops the app via Settings, Android will not wake it for any push — including high-priority FCM — until the user manually relaunches it. This is an Android OS policy and cannot be worked around in code. |
| OEM battery savers (Xiaomi/MIUI, Huawei/EMUI, Samsung/One UI, OnePlus, OPPO/ColorOS) | Silent & visible | Proprietary battery managers kill background processes and block push delivery even for high-priority messages. Users may need to add the app to an Autostart or Protected apps whitelist in the device's battery settings. |
| No network / poor signal | Silent & visible | FCM holds messages offline until the device reconnects, up to the time_to_live window in the payload (default 4 weeks). |
Send silent pushes as data-only FCM payloads (no notification block) with "silent": "true" in data. If a notification block is present, Firebase renders the notification itself and bypasses the SDK entirely.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
FIS_AUTH_ERROR | Google rejected the Firebase API key for this build | See FIS_AUTH_ERROR below |
| Token never arrives | google-services.json not in app/ | Confirm file placement and re-sync Gradle |
Token never arrives; Logcat shows c2dm: [-19,ERR_SERVICE_NOT_AVAILABLE,0,0] or SERVICE_NOT_AVAILABLE | The device can't reach Firebase's servers through Google Play services | See SERVICE_NOT_AVAILABLE below |
JVM-target mismatch | App and SDK JVM targets differ | Set both to VERSION_17 |
| No push in background | notification block handled by system tray | Send data-only FCM payload for full SDK control |
| Silent push shown as a notification | silent key missing from data | Add "silent": "true" to the data payload |
| Silent push listener never fires | Listener registered in an Activity, or payload has a notification block | Register in Application.onCreate() and send a data-only payload |
| Cold-start tap ignored | handleNotificationTapIntent not called in onCreate | Add to both onCreate and onNewIntent |
| White square icon | No com.appsonair.apppush.default_notification_icon meta-data (SDK falls back to the launcher icon) | Add the meta-data. See Step 3 |
| White or solid square icon | The drawable is full-colour or has an opaque background | Use a white silhouette on a transparent background |
| Icon correct in foreground, wrong in background | Firebase rendered a notification-block message and the Firebase meta-data is missing | Add the com.google.firebase.messaging.default_notification_icon / _color entries, pointing at the same resources |
small_icon ... not found in res/drawable in Logcat | Payload names a drawable that doesn't exist (or is in mipmap) | Put the file in res/drawable* and send the name without its extension |
| Accent color ignored | Meta-data uses android:value="#..." | Use android:resource="@color/..." |
| Image missing | URL isn't HTTPS or the download timed out | Use HTTPS. The image must respond within 10 s and be ≤ 10 MB |
SERVICE_NOT_AVAILABLE: no FCM token
Logcat repeats c2dm: [-19,ERR_SERVICE_NOT_AVAILABLE,0,0] and onError reports TOKEN_FETCH_FAILED. Google Play services can't reach Firebase, so this is a device or network issue, not an SDK or config issue. The SDK retries for about 100 seconds, then waits until the next app launch.
Fix, then force-stop and relaunch the app:
- Switch between Wi-Fi and mobile data. Office or public Wi-Fi often blocks FCM (TCP ports 5228–5230).
- Turn off VPN, Private DNS and ad blockers, and turn on automatic date & time.
- Update Google Play services, and allow it background data and unrestricted battery.
- On Xiaomi, OPPO, vivo, Huawei and similar phones, turn on Autostart and set battery saver to No restrictions for Google Play services and your app.
- On an emulator, use a system image with Google Play.
FIS_AUTH_ERROR: API key rejected
Logcat shows FIS_AUTH_ERROR and onError reports TOKEN_FETCH_FAILED. Google rejected the Firebase API key in google-services.json for this build, so this is a configuration issue. The SDK doesn't retry it.
Fix in Google Cloud Console → APIs & Services → Credentials, on the Android key from google-services.json:
- Under Application restrictions, list your package name with the SHA-1 of the certificate this build is signed with. Debug, release and Play App Signing each have a different SHA-1, so add every one you use. Print them with
./gradlew signingReport. - Under API restrictions, allow Firebase Installations API and Firebase Cloud Messaging API, or set Don't restrict key.
- Check that
google-services.jsonbelongs to the same Firebase project and package name as the build.
Rebuild and reinstall the app after changing the key.
Setup Checklist
-
google-services.jsonis inapp/, and the Google Services plugin is applied - JitPack repository and the SDK dependency are added, and Gradle is synced
-
AppsonairAppIdmeta-data is inAndroidManifest.xml - A white-on-transparent notification icon is in
res/drawable* - The accent color is in
res/values/colors.xml - Both the AppsOnAir and Firebase icon/color meta-data point at those resources
-
AppPushService.initialize(this)is called inApplication.onCreate() -
handleNotificationTapIntentis called inonCreateandonNewIntent - Notification permission is requested (Android 13+)
Log Levels
Set before initialize():
NONE- Silent (default for production)FATAL- Fatal errors onlyERROR- ErrorsWARN- WarningsINFO- General infoDEBUG- Debug infoVERBOSE- All messages (use during development)