Android SDK setup
Add the Android SDK, call initialize once, and let the device register for push.
The Android SDK is a Kotlin library. Its manifest entries merge into your app automatically, so there is nothing to copy by hand.
Quick start
- Create the app in the portal. Choose Google Android (FCM) and upload your Firebase service account JSON. The channel shows Active only once that file is saved. Copy the App ID from the install page.
- Add Firebase to your project. Add the Google Services plugin and put
google-services.jsonin your app module. - Add the dependency. One line, no repository or token:
implementation("io.github.pushfyre-hub:sdk-android:1.0.2"). - Initialize once in
Application.onCreatewith your App ID and API address. - Ask for notification permission from an Activity (Android 13 and later).
- Check it works. Run the app, then open Audience in the portal. The device appears there. Send yourself a push from Test Subscription.
Requirements
minSdk 24or higher- The Google Services Gradle plugin and a
google-services.jsonin your app module. This is the same Firebase setup FCM itself needs. - Your app id and API address, shown on the app's install page in the portal
Set up Firebase
PushFyre delivers through Firebase Cloud Messaging, so your app needs the standard Firebase setup. Download google-services.json from your Firebase project settings into the app/ folder, then add the plugin:
// build.gradle.kts (project)
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")
}Add the dependency
The SDK is on Maven Central, so there is no repository or token to set up. New Android projects already include mavenCentral(); if yours does not, add it next to google().
// app/build.gradle.kts
dependencies {
implementation("io.github.pushfyre-hub:sdk-android:1.0.2")
}// settings.gradle.kts (only if mavenCentral() is missing)
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
}Initialize the SDK
Call initialize in Application.onCreate, not in an Activity, so registration happens once per process. Use the Java tab for a Java app. PushFyreConfig has no Java default arguments, so that sample passes every constructor value.
import com.wonindia.push.PushFyre
import com.wonindia.push.PushFyreConfig
import com.wonindia.push.PushFyreEnvironment
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
PushFyre.initialize(
this,
PushFyreConfig(
appId = "app_49e692ad",
apiBaseUrl = "https://push.example.com/api/v1",
environment = if (BuildConfig.DEBUG) PushFyreEnvironment.TEST
else PushFyreEnvironment.PROD
)
)
}
}ic_stat_pushfyre_default. Without it Android shows your launcher icon as a plain white square in the status bar.Ask for notification permission
Android 13 and later require a runtime permission. Call this from an Activity at a moment that makes sense to the user. It does nothing on older versions.
PushFyre.requestNotificationPermission(this)Registration does not depend on the permission, so a device stays reachable even before the user decides.
Identify and tag the device
// After login
PushFyre.login(context, externalUserId)
PushFyre.sendTag(context, "isPremium", "true")
PushFyre.sendTags(context, mapOf("plan" to "annual", "segmentId" to "8"))
PushFyre.removeTag(context, "plan")Handle taps
By default a tapped notification opens its link externally, or your app if it has none. To route inside your app, register a handler and return true when you handled the tap.
PushFyre.setTapHandler { context, targetUrl, actionId ->
when (actionId) {
"view_chart" -> { openChart(context); true }
else -> false // let the SDK open targetUrl
}
}actionId tells you which action button was pressed, and is null when the notification body was tapped.
In-app messages
The same SDK shows in-app messages created in the portal. Nothing extra is needed for a message set to appear on app open. To show one on a particular screen or action, call PushFyre.trigger(context, "event_name", properties). In the campaign, add an In-App Trigger whose key is event_name and whose value is true. That call is also stored as a custom event. An in-app Action name click action reaches your tap handler with that action id. See In-app messages and Custom events.
WhatsApp phone number
Ask for the number in your own screen, and explain that it will be used for WhatsApp messages from your business. Call this only after the person agrees. The SDK does not show that dialog for you. An international number such as +14155552671 is stored and sent again on later registrations.
PushFyre.setWhatsAppPhone(context, "+14155552671")
// When they withdraw consent
PushFyre.clearWhatsAppPhone(context)setWhatsAppPhone unless the person has agreed. A WhatsApp campaign reaches only devices that opted in this way. See WhatsApp.See it, then create an account
The demo shows a sample notification. It does not send a message. Create an account when you are ready to register a device.