Android push notifications
Register Android devices for push notifications with the PostHog Android SDK, and capture when users open them. Before you start, connect an FCM channel for the same Firebase project as your app.
Requirements
- Android SDK 3.58.0 or later. Versions before 3.72.0 take
apiKeyinstead ofprojectToken. - Firebase Cloud Messaging set up in your app, with
firebase-messagingon the classpath. - The
POST_NOTIFICATIONSpermission, which your app asks for on Android 13 and later.
Register the device
The SDK registers the device's FCM token and captures opens by default:
Call setup() in Application.onCreate, not in an Activity. The SDK reads a notification tap when the launch Activity is created, so it has to be set up before that. If you set it up in an Activity, it misses taps that launch the app.
The SDK fetches the token at startup. Firebase sends a new token to onNewToken, which the SDK can't see, so forward it:
Register manually
If you manage tokens yourself, set capturePushNotificationSubscriptions to false and register the token with your Firebase project ID as the app ID:
If you don't call reset() at sign-out, unregister the device yourself:
Firebase installation IDs
If your app turns on the firebase_messaging_installation_id_enabled manifest flag, the SDK registers the Firebase installation ID at startup instead of the FCM token (Android SDK 3.75.0 and later). Forward onRegistered instead of onNewToken, so the device registers again when Firebase calls it:
Capture opens
The SDK captures a tap that launches your app from the system tray. It recognizes the tap by the google.message_id extra that Firebase puts on the intent.
A tap that arrives while your app is running goes to Activity.onNewIntent, which the SDK can't see. Forward it from your launcher activity (Android SDK 3.62.0 and later):
Your launcher activity needs android:launchMode="singleTop". Otherwise the system resumes the task and doesn't deliver the tap here. This call can't count a tap twice, because the SDK deduplicates it by message ID.
The SDK can't detect notifications that your app draws from a data message, or push delivered outside FCM. Capture those yourself:
From Android SDK 3.65.0, this call skips a notification that PostHog sent if the SDK captured it in the last 5 minutes.
Identity verification
If your channel uses identity verification, return a token from your backend through pushIdentityProvider. Call completion exactly once:
Troubleshooting
| Problem | What to check |
|---|---|
| The token never registers | firebase-messaging is on the classpath, google-services.json is in place, and you forward onNewToken. |
| A push never arrives | The channel's Firebase project matches your app, and the user granted POST_NOTIFICATIONS. |
| Taps while the app runs aren't captured | Your launcher activity uses singleTop and forwards onNewIntent. |
For problems that apply to every SDK, see push troubleshooting.





