Docs Add PusherHub to your app
Android push notifications (Kotlin): add the SDK step by step
Every step with a picture from a real Kotlin app: where the SDK file goes, the Firebase lines in Gradle, the manifest and the code in MainActivity.
8 min read
All guides
- Get started with PusherHub
- Create a Firebase project
- Get your Firebase service account file
- Find your Sender ID
- iOS push notifications: add your Apple push key to Firebase
- Add push notifications to your app
- Flutter
- Android (Kotlin)
- Java
- React Native
- iOS (Swift)
- Unity
- Send a test push notification
- Send your first push notification
Download PusherHub.kt
In the dashboard, open
Applications
your app
SDK Integration
and pick Android (Kotlin) ①. Click Download PusherHub.kt ②. Under the button is the folder it goes in ③: your app's package with pusherhub on the end.
Every step below is on this tab too, with your own keys and package already filled in — copy the code from there.
Put the two files in your project
In Android Studio, switch the file list at the top left to Project.
google-services.json① goes in the app folder, next to the app'sbuild.gradle.kts.PusherHub.kt② goes in a new pusherhub folder inside your package. Right-click your package (herecom.example.myapp), choose New Package , typepusherhub, then drag the file into it.- Open
PusherHub.kt: its first line ③ already has your own package. The file was made for your app, so don't change anything in it.
Add the Google services plugin to the project
Open the project's build.gradle.kts — the one outside the app folder, shown as build.gradle.kts (MyApp). Inside plugins { }, add ①:
id("com.google.gms.google-services") version "4.4.3" apply false
Android Studio offers to Sync Now ②. You can wait and sync once, after the next step.
Add Firebase to the app
Open the app's build.gradle.kts, shown as build.gradle.kts (:app).
- Inside
plugins { }, addid("com.google.gms.google-services")①. - Inside
dependencies { }, add Firebase Cloud Messaging ②. PusherHub needs nothing else. - Click Sync Now ③ and wait for it to finish.
implementation(platform("com.google.firebase:firebase-bom:34.4.0"))
implementation("com.google.firebase:firebase-messaging")
Add permissions and the service to AndroidManifest.xml
Open app/src/main/AndroidManifest.xml and add these three things to the manifest you already have — don't replace it. The code is in step 3 on your SDK Integration tab.
- The permissions ①, above
<application>.ACCESS_COARSE_LOCATIONis only needed if you want each phone's state and city (step 6). - A second
<intent-filter>② inside yourMainActivity's<activity>. It lets a tap on a notification open your app and be counted. The name says Flutter, but every PusherHub notification uses it, Kotlin apps too. - The
<service>③ inside<application>. It's what receives the notifications. Its name is your package plus.pusherhub.PusherHubMessagingService.
Start PusherHub in MainActivity
Open MainActivity.kt and add the code from step 4 on your SDK Integration tab — your keys and server are already filled in. (In the picture they're placeholders.)
- The import ①. Android Studio can add it for you: click on
PusherHuband press Alt+Enter (Option+Return on a Mac). PusherHub.initialize(…)② inonCreate, with your App key and Public key.PusherHub.registerDevice { … }③ gets the phone's push token, asks the user to allow notifications and adds the phone to PusherHub.collectDeviceMetadata()inside it is optional: it adds the phone's brand, model, language and country, plus state and city if you added the location permission.PusherHub.handleIntent(intent)④ counts the tap when someone opened the app from a notification.
Pass taps and answers on to PusherHub
Lower down in MainActivity, add these three functions. If you already have one, just add its PusherHub line to it.
onNewIntent① — a notification tapped while the app was open in the background.onRequestPermissionsResult② — tells PusherHub what the user answered when asked to allow notifications or location.onResume③ — optional: shows your in-app messages each time the app is opened. Leave it out if you don't use them.
Optional: log the user in
If your app has its own sign-in, tell PusherHub who's using the phone. Then you can send to one person by your own user ID. It's remembered, even after the app restarts, until logout().
// When someone signs in: PusherHub.login(currentUserId) // When they sign out: PusherHub.logout()
Optional: open a screen when a notification is tapped
Put your own data in Custom Data when you create a notification — say {"campaign_id": "232"} — and your app gets it back whenever someone taps that notification, whether the app was open, in the background or closed. Add onNotificationOpened to the PusherHub.initialize(…) from step 6:
PusherHub.initialize(
context = this,
appKey = "YOUR_APP_KEY",
publicKey = "YOUR_PUBLIC_KEY",
baseUrl = "YOUR_SERVER",
onNotificationOpened = { data ->
data["campaign_id"]?.let { campaignId ->
startActivity(Intent(this, CampaignActivity::class.java).putExtra("campaign_id", campaignId))
}
},
)
It runs from handleIntent, so keep both of its calls from steps 6 and 7. Every value arrives as text ("232"). This needs PusherHub.kt from 24 October 2026 or later — download it again if yours is older.
Run the app on a phone
Click Run ▶ to open the app on a phone or an emulator with Google Play, and tap Allow when it asks about notifications. Within a few seconds the phone shows up in PusherHub under Devices.