Early access · launching soon. Request access

Early access

Early access · launching soon
Product
IntelligenceEarly access. Designed and in development. No results yet. See what's left on the roadmap.
Developers
Resources
Request access

A person reads every request.

SDKsEarly accessDesigned and in development. No results yet. See what's left on the roadmap.

Android push notifications quickstart (Kotlin)

Oricato Team Last updated SDK 1.0.1

Early access · launching soon. This guide adds the Oricato Android SDK (com.oricato:push:1.0.1) to a native Android app written in Kotlin or Java. When you finish, your app registers with Oricato, shows notifications sent from the dashboard or the REST API, and passes taps to your code.

The SDK uses your app’s own Firebase project: Oricato sends through Firebase Cloud Messaging (FCM) with a key you upload, and the SDK receives the push on the device. The examples use the sample app Lingora (com.lingora.app). Use your own application ID.

Building with Flutter? Use the Flutter quickstart instead.

Prerequisites

  • Android project: minSdk 21 or higher, compileSdk 34 or higher (the SDK itself is built with compileSdk 36), Android Gradle Plugin 8.x, and Kotlin 1.9+ or Java 11+.
  • Firebase: an Android app with your application ID in your app’s Firebase project, and its google-services.json file in your app module (app/google-services.json).
  • An Oricato project with its Project ID (a UUID) and API address. Both are shown in the dashboard under Project → Settings → Add Oricato to your app. In production the API address is https://api.oricato.com: no path, no /api/v1, no trailing slash.
  • A Firebase key uploaded in the dashboard (Project settings → Firebase key), from the same Firebase project as google-services.json, created for a least-privilege service account. See Firebase and APNs credentials.
  • The SDK kit, version 1.0.1. Its android/maven/ folder is a local Maven repository with com.oricato:push:1.0.1.

In the code below, replace <ORICATO_PROJECT_ID> with your Project ID and <ORICATO_API_ADDRESS> with your API address.

Steps

1. Add the SDK’s Maven repository

Copy the kit’s android/maven/ folder into your project next to settings.gradle.kts and name it oricato-maven/. Keeping it inside the project means the app builds on any machine and in CI. Then declare it in settings.gradle.kts:

// settings.gradle.kts
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven { url = uri("oricato-maven") } // relative to settings.gradle.kts, or an absolute path
    }
}

If your project uses repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS), the repository must be in settings.gradle.kts as shown, not in a module’s build.gradle.kts.

Groovy projects use the same block in settings.gradle:

// settings.gradle
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven { url = uri("oricato-maven") }
    }
}

2. Add Firebase Messaging and the SDK to Gradle

Skip the lines your app already has.

// root build.gradle.kts
plugins {
    id("com.google.gms.google-services") version "4.4.2" apply false
}
// app/build.gradle.kts
plugins {
    id("com.android.application")
    id("com.google.gms.google-services")
}

dependencies {
    implementation(platform("com.google.firebase:firebase-bom:33.16.0")) // 34.x needs minSdk 23
    implementation("com.google.firebase:firebase-messaging")
    implementation("com.oricato:push:1.0.1")
}

com.oricato:push brings firebase-messaging (24.0.0, or the newer version your app already uses, because it is an api dependency), androidx.core, androidx.work and androidx.lifecycle:lifecycle-process. Its R8 and ProGuard rules ship inside the AAR, so you add nothing to proguard-rules.pro.

Firebase BoM 34 and later. BoM 34+ resolves firebase-messaging 25.x, which requires minSdk 23 in your app. Apps with minSdk 21 or 22 stay on BoM 33.x (firebase-messaging 24.x). The SDK is type-checked against both firebase-messaging 24.0.0 and 25.1.0, so it works with either.

3. Initialize the SDK in Application.onCreate

package com.lingora.app

import android.app.Application
import com.oricato.push.Oricato

class App : Application() {
    override fun onCreate() {
        super.onCreate()
        Oricato.initialize(
            this,
            projectId = "<ORICATO_PROJECT_ID>",
            apiBaseUrl = "<ORICATO_API_ADDRESS>",
            defaultSmallIcon = R.drawable.ic_stat_notification, // optional, white-on-transparent
        )
    }
}

From Java, it’s one line:

Oricato.initialize(this, "<ORICATO_PROJECT_ID>", "<ORICATO_API_ADDRESS>", R.drawable.ic_stat_notification);

Register the class in your manifest (<application android:name=".App" ...>) if your app doesn’t have one yet. initialize is idempotent and cheap: call it on every app start. Release builds accept only https:// addresses. Other Oricato methods are safe to call from any thread, and calls made before initialize are queued and applied once it runs.

4. Declare the messaging service in your manifest (required)

Required: without this step your app receives nothing. The SDK’s own manifest deliberately does not declare com.oricato.push.OricatoMessagingService, so two services never compete for com.google.firebase.MESSAGING_EVENT. Your app must declare it (or a subclass), or forward pushes from its own FirebaseMessagingService. We have seen integrations where everything else was correct, the dashboard showed the phone, and no notification ever arrived, because this declaration was missing.

Pick one of the three options. Only one service in your app may handle MESSAGING_EVENT.

Option A: your app has no FirebaseMessagingService of its own (most apps). Add this inside <application> in app/src/main/AndroidManifest.xml:

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

Option B: you also receive other (non-Oricato) pushes. Subclass the SDK’s service and declare your subclass in the manifest instead, with the same <intent-filter>:

package com.lingora.app

import com.google.firebase.messaging.RemoteMessage
import com.oricato.push.OricatoMessagingService

class AppMessagingService : OricatoMessagingService() {
    override fun onNonOricatoMessageReceived(message: RemoteMessage) { /* your own pushes */ }
    override fun onNewFcmToken(token: String) { /* optional */ }
}
<service
    android:name=".AppMessagingService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

If your subclass overrides onMessageReceived or onNewToken directly, it must call super.

Option C: your app already has a FirebaseMessagingService. Keep it and forward to the SDK:

package com.lingora.app

import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.oricato.push.Oricato

class AppMessagingService : FirebaseMessagingService() {
    override fun onMessageReceived(message: RemoteMessage) {
        if (Oricato.handleRemoteMessage(this, message)) return // an Oricato push: handled
        // ... your own pushes
    }

    override fun onNewToken(token: String) {
        Oricato.onNewToken(this, token)
        // ... your own token handling
    }
}

handleRemoteMessage returns true when the push was Oricato’s and has been handled, and false when your code should process it. If you use the firebase-messaging 25.1 registration API (FirebaseMessaging.register() and onRegistered), call Oricato.onNewToken(this, token) from onRegistered as well.

All three options work even when Android starts your process only to deliver the push: the SDK loads its saved state on its own. One caveat: until initialize has run once on that installation, pushes are passed on untouched, so open the app once after installing it.

5. Add a notification icon and keep resources from shrinking

  1. Add a white-on-transparent status-bar icon, for example app/src/main/res/drawable/ic_stat_notification.xml (Android Studio → New → Vector Asset or Image Asset → Notification Icons), and pass it as defaultSmallIcon in step 3. Without one, the SDK uses its own bell icon.
  2. The server refers to icons (ic_stat_*) and channel sounds (res/raw/) by name, which resource shrinking can’t see. Add app/src/main/res/raw/oricato_keep.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:keep="@drawable/ic_stat_*,@raw/*" />
  1. Custom channel sounds go in app/src/main/res/raw/ (for example chime.mp3 is the sound name chime in the dashboard). A channel whose sound file is missing is not created. See Android notification channels.

6. Ask for notification permission (Android 13+)

The SDK declares POST_NOTIFICATIONS. Ask at a moment that makes sense to the person, for example after they turn on reminders, not on first launch:

Oricato.requestPermission(activity) { granted -> /* update your UI */ }
val status = Oricato.getPermissionStatus(context) // GRANTED, DENIED, NOT_DETERMINED
Oricato.openNotificationSettings(context)          // when people switched notifications off

Below Android 13 there is no prompt and the callback receives the current state. Whichever prompt answers (yours, another SDK’s or requestPermission), and any change in the phone’s Settings, is reported to Oricato as soon as the app is back in the foreground. See Notification permission for timing advice. The same step on other platforms: iOS quickstart and Flutter quickstart.

7. Handle taps and foreground notifications

Register handlers early, for example in Application.onCreate after initialize:

Oricato.onNotificationOpened { n ->
    // main thread: n.messageId, n.title, n.body, n.launchUrl, n.additionalData
}

Oricato.onForegroundNotification { n ->
    true // return false to hide it while the app is open ("delivered" is still reported)
}

Oricato.setLaunchUrlsAutoOpen(false) // default true: a tap opens the launch URL (deep link or web page) itself
  • onNotificationOpened always runs on the main thread. The latest tap of the last 5 minutes is kept and delivered when you register the handler, so a tap that started the app is not lost.
  • n is an OricatoNotification: messageId: String, title: String?, body: String?, launchUrl: String? and additionalData: Map<String, String>.
  • onForegroundNotification runs on the Firebase messaging thread, not the main thread, and must return quickly.
  • With auto-open on (the default), a tap opens the launch URL exactly once. Without a URL, or with auto-open off, the tap brings your app’s existing task to the front.

8. Optional: forward taps in “Shown by Android” mode

Skip this step unless the project’s Android display setting is Shown by Android (the default is Shown by the Oricato SDK). In that mode Android renders background pushes itself and the SDK only sees the tap through your launcher activity’s intent:

package com.lingora.app

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.oricato.push.Oricato

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Oricato.handleIntent(this, intent)
    }

    override fun onNewIntent(intent: Intent) {
        super.onNewIntent(intent)
        Oricato.handleIntent(this, intent)
    }
}

System mode reports opens but almost no delivery receipts. The default SDK mode supports images, channels and “arrived” reports.

9. Optional: identify users and add tags

Link the installation to your own user ID, segment with tags and record conversions:

Oricato.setLanguage("es")               // the language your app shows; null = follow the app locale again
Oricato.setExternalUserId("u_9f2b1c03") // opaque pseudonymous ID only, never an email or phone number
Oricato.setExternalUserId("u_9f2b1c03", hashFromYourBackend) // when the project verifies external IDs
Oricato.setTags(mapOf("plan" to "pro", "trial" to null))       // merge; null or "" removes a key (up to 50 keys)
Oricato.optOut()                        // app-level switch; Oricato.optIn() turns it back on
Oricato.trackEvent("purchase")          // conversion name, ^[a-z0-9_]{1,40}$

Without setLanguage, the SDK uses the locale of your resumed activities, then the device locale. See Users, external IDs and tags and Languages and localized messages.

Test against a local server (optional)

On the Android emulator, apiBaseUrl may be http://10.0.2.2:8080 (your computer’s address from the emulator) only in debuggable builds. Release builds require https://. Android also blocks cleartext traffic by default, so allow it for debug builds only with a debug network security config:

<!-- app/src/debug/res/xml/network_security_config.xml -->
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="false">10.0.2.2</domain>
    </domain-config>
</network-security-config>
<!-- app/src/debug/AndroidManifest.xml -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application android:networkSecurityConfig="@xml/network_security_config" />
</manifest>

If your main manifest already sets android:networkSecurityConfig, the manifest merge fails. In that case declare xmlns:tools="http://schemas.android.com/tools" on the debug <manifest> and add tools:replace="android:networkSecurityConfig" to the debug <application>.

Verify it works

  1. Turn on debug logs while you test, for example right before initialize:

    import com.oricato.push.OricatoLogLevel
    
    Oricato.setLogLevel(OricatoLogLevel.DEBUG) // logcat tag "Oricato"

    Then filter logcat by the tag Oricato. The default level is WARN.

  2. Install a debug build on your phone, open the app once and allow notifications.

  3. Log the installation’s ID so you can find this phone later:

    import android.util.Log
    
    Log.d("OricatoDemo", "Subscription ID: ${Oricato.getSubscriptionId()}")

    getSubscriptionId() returns null until the first successful initialize: also when initialize rejected its arguments (a Project ID that is not a UUID, or http:// in a release build) or the SDK could not save its state.

  4. In the dashboard, open your project → Verify setup. The checklist should show Firebase key works, then Your app connected with your phone’s model.

  5. Press Send test notification. What you should see: the notification appears on the phone and the checklist ticks arrived. Tap it: the checklist ticks opened and your onNotificationOpened handler runs.

  6. Optional: under Keep this phone for testing, name the phone and press Mark as test device, so the composer’s “Try it on your phone first” sends to it. You can also search the subscription ID in Audience.

Troubleshooting

Nothing arrives, but the phone shows up in the dashboard

The messaging service is missing. Check that your merged manifest contains exactly one service with the com.google.firebase.MESSAGING_EVENT action, and that it is com.oricato.push.OricatoMessagingService, your subclass of it, or your own service that calls Oricato.handleRemoteMessage. See step 4.

No FCM token, or Firebase Installations reports “BAD CONFIG”

If the dashboard says the phone hasn’t allowed notifications while permission is granted, the phone may have no FCM token. A common cause is the Android API key in google-services.json being restricted to Android apps without your app’s SHA-1 fingerprint. Firebase Installations is then rejected (“BAD CONFIG” in its logs) and no token is issued, so nothing can be sent to that phone, including release users whose signing certificate is missing.

To fix it, open Google Cloud Console → APIs & Services → Credentials, open the Android key used by your app, and under Android apps add your package name (com.lingora.app in this example) with the SHA-1 of every certificate that signs it: the debug key, your upload or release key, and the Play App Signing key. Print the local fingerprints with:

./gradlew signingReport

On a debug build you can confirm the token by reading the SDK state (redact the token before you share it):

adb shell run-as com.lingora.app cat no_backup/oricato_push/state.json

A "fcm_token": null value means Firebase never issued a token.

Logcat says “Wrong Project ID” or “The Oricato API answered 404”

Both messages mean the server answered HTTP 404, and in both cases the SDK stops all calls until the app restarts.

  • “Wrong Project ID: the server does not know this project”: the server returned the error code project_not_found. The Project ID passed to initialize doesn’t exist on that server.
  • “The Oricato API answered 404 (…). Check apiBaseUrl”: any other 404, for example a wrong host or an apiBaseUrl with a path such as /api/v1. initialize accepts such an address, but every call then misses the API.

Copy both values again from Project → Settings → Add Oricato to your app, then restart the app. apiBaseUrl must have no path (no /api/v1) and no trailing slash.

A release build never registers

Logcat shows “initialize: apiBaseUrl must use https:// in release builds”. http:// addresses work only in debuggable builds. Use your https:// API address in release builds.

The icon shows as a white or gray square

Android draws every non-transparent pixel of a status-bar icon in one color. Use a white-on-transparent icon from Image Asset → Notification Icons, pass it as defaultSmallIcon, and keep oricato_keep.xml from step 5 so release builds don’t strip ic_stat_* drawables.

A channel’s sound doesn’t play, or the channel is missing

Logcat shows “Channel ‘…’ not created: sound res/raw/… is missing”. Add the sound file to res/raw/ and keep it with oricato_keep.xml. Android fixes a channel’s sound and vibration when the channel is created: to change them, create a channel with a new ID in the project’s channel list. A channel ID you send must also exist in that list. See Android notification channels.

Notifications arrive silently on some phones

Some manufacturers’ Android versions (for example TECNO HiOS) can demote an app’s notifications to silent. On the phone, open Settings → Apps → your app → Notifications and check that the app and its channels are allowed to make sound and pop up. Oricato.openNotificationSettings(context) opens that screen from your app.

More fixes: Troubleshooting delivery.

Next steps

Related

Get early access to Oricato.

Founding teams get early access, free help moving from OneSignal, and a founding discount.

We use this to reply, plan your invitation and set up your account. Privacy Policy

A person reads every request.

Or get the monthly newsletter