Learn how to send push notifications to users when they are offline.
Firebase is shutting down FCM legacy API on June 20, 2024. Migrate to FCM HTTP v1 API before this date in order to keep Android Push Notifications working. Follow steps in our migration guide.
In case of any issues please reach us out via our Help Center.
Push Notifications provide a way to deliver some information to a user while they are not using your app actively. The following use cases can be covered by push notifications:
Visit Key Concepts page to learn the most important QuickBlox concepts.
HTTP v1 API it’s recommended solution.
HTTP v1 API
To generate a new service account key, you need to:
To navigate to the push notifications section:
Note: we will remove the Server key tab when it will be discontinued by FCM, you will by default only have the service account key section on the dashboard.
To upload your service account key:
Note: When setting up your environment, it’s important to distinguish between development and production modes. If you’ve uploaded a development certificate, it will only function for subscriptions created in the development environment, and likewise for production. This separation ensures seamless testing and deployment of push notifications across different environments.
API (Legacy) it’s deprecated, not recommended
How to enable Cloud Messaging API (Legacy)
To enable Cloud Messaging API (legacy) instead of Firebase Cloud Messaging API (HTTP V1), please log in to your Firebase account, afterward select your Application and do the following:
To start working with push notifications functionality, you need to configure it. At first, you should create a Firebase account if you haven’t it. Then you should configure your Firebase project and obtain the API key.
build.gradle
file.build.gradle
file.build.gradle
file.google-services.json
file from your Firebase Project dashboard and put it into your app folder in your Android project.com.quickblox.messages.TYPE
- can be GCM
or FCM
.com.quickblox.messages.SENDER_ID
- your sender ID from google console (for example, 639872757929).com.quickblox.messages.QB_ENVIRONMENT
- can be DEVELOPMENT
or PRODUCTION
.QBFcmPushListenerService
and QBFcmPushInstanceIDService
in AndroidManifest.QuickBlox Android SDK provides automatic push subscription management. It means that you do not need to bother how to get FCM device token, create push subscription, and what to do with the received data. Thus, you can reduce your code and make it cleaner.
A single user can have up to 10 subscriptions on different devices.
Here you can use a global setting to enable or disable delivery of push notifications. Set this parameter only once.
To be aware of what is happening with your push subscription, whether you’re subscribed successfully or not, you can use the QBSubscribeListener
. Just add QBSubscribeListener
right after the QBSettings.getInstance().init()
code.
If you do not want to use the automatic push subscription feature, then do the following:
SubscribePushStrategy.NEVER
as the main strategy.In this case, you need to subscribe and unsubscribe manually using the following methods:
QBFcmPushListenerService
you need to handle when the token is refreshed:QBFcmPushListenerService
to the Manifest file.The token
is a device registration token generated by the APNs or GCM/FCM. The token can be unregistered by the APNs or GCM/FCM anytime. In this case, the device should be registered again and obtain a new token. When a new token is obtained, a new subscription should be created.
You can manually initiate sending of push notifications to a user/users on any event in your application. To send a push notification, you should use QBEvent
, fill its fields with push notification parameters (payload) and set push recipients.
You can send only FCM data messages to the Android app. QuickBlox doesn’t support FCM notification messages.
To process FCM data messages on your app when the app is in the background, you need to handle them. If not handled, they will not pop on the screen even if the app has received such push notification. See FCM documentation to learn more about data messages.
You can send APNs VoIP notifications to the iOS app. However, if the iOS app is not subscribed to APNs VoIP notifications or the APNs VoIP certificate has expired, the regular APNs will be delivered instead of APNs VoIP.
To receive push notifications, you should register the BroadcastReceiver
.
Or use the onMessageReceived()
in your class that extends QBFcmPushListenerService
.
Cause 1: incorrect FCM server key is set in the Dashboard.
Tip: check if you put a correct FCM server key into the FCM API key field in the Dashboard => YOUR_APP => Push Notifications => Settings. See how to obtain the FCM server key and where to set it here.
It is possible that you are using the FCM sender ID instead of the FCM server key in the Dashboard. Try to send the message from a Firebase console directly. If a message has appeared, a problem is in the FCM server key. If the FCM server key is incorrect, then there will be the following error: error 401 (Unauthorized, check your App auth_key)
. This means that the QuickBlox server wasn’t able to authorize on the Firebase server.
Cause 2: incorrect FCM sender ID in the google-services.json
file.
Tip: check if you added a correct google-services.json
file to your project.
Cause 3: the push is sent to the production zone while the device is subscribed to the development zone or vice versa.
Tip: check if you put the same FCM server key into the FCM API key field in the Dashboard => YOUR_APP => Push Notifications => Settings for development and production to reduce the risk of error.
Cause: a device registration token is invalid.
The device registration token is represented as token
within the system. See this section to learn how to subscribe a device to push notifications.
Tip: check if the device registration is correct. The device registration token can be invalid due to a number of reasons:
For all these cases, remove the invalid device registration token and stop using it to send messages. Then, obtain a new token and make sure to create a new subscription with a valid token.
Learn how to send push notifications to users when they are offline.
Firebase is shutting down FCM legacy API on June 20, 2024. Migrate to FCM HTTP v1 API before this date in order to keep Android Push Notifications working. Follow steps in our migration guide.
In case of any issues please reach us out via our Help Center.
Push Notifications provide a way to deliver some information to a user while they are not using your app actively. The following use cases can be covered by push notifications:
Visit Key Concepts page to learn the most important QuickBlox concepts.
HTTP v1 API it’s recommended solution.
HTTP v1 API
To generate a new service account key, you need to:
To navigate to the push notifications section:
Note: we will remove the Server key tab when it will be discontinued by FCM, you will by default only have the service account key section on the dashboard.
To upload your service account key:
Note: When setting up your environment, it’s important to distinguish between development and production modes. If you’ve uploaded a development certificate, it will only function for subscriptions created in the development environment, and likewise for production. This separation ensures seamless testing and deployment of push notifications across different environments.
API (Legacy) it’s deprecated, not recommended
How to enable Cloud Messaging API (Legacy)
To enable Cloud Messaging API (legacy) instead of Firebase Cloud Messaging API (HTTP V1), please log in to your Firebase account, afterward select your Application and do the following:
To start working with push notifications functionality, you need to configure it. At first, you should create a Firebase account if you haven’t it. Then you should configure your Firebase project and obtain the API key.
build.gradle
file.build.gradle
file.build.gradle
file.google-services.json
file from your Firebase Project dashboard and put it into your app folder in your Android project.com.quickblox.messages.TYPE
- can be GCM
or FCM
.com.quickblox.messages.SENDER_ID
- your sender ID from google console (for example, 639872757929).com.quickblox.messages.QB_ENVIRONMENT
- can be DEVELOPMENT
or PRODUCTION
.QBFcmPushListenerService
and QBFcmPushInstanceIDService
in AndroidManifest.QuickBlox Android SDK provides automatic push subscription management. It means that you do not need to bother how to get FCM device token, create push subscription, and what to do with the received data. Thus, you can reduce your code and make it cleaner.
A single user can have up to 10 subscriptions on different devices.
Here you can use a global setting to enable or disable delivery of push notifications. Set this parameter only once.
To be aware of what is happening with your push subscription, whether you’re subscribed successfully or not, you can use the QBSubscribeListener
. Just add QBSubscribeListener
right after the QBSettings.getInstance().init()
code.
If you do not want to use the automatic push subscription feature, then do the following:
SubscribePushStrategy.NEVER
as the main strategy.In this case, you need to subscribe and unsubscribe manually using the following methods:
QBFcmPushListenerService
you need to handle when the token is refreshed:QBFcmPushListenerService
to the Manifest file.The token
is a device registration token generated by the APNs or GCM/FCM. The token can be unregistered by the APNs or GCM/FCM anytime. In this case, the device should be registered again and obtain a new token. When a new token is obtained, a new subscription should be created.
You can manually initiate sending of push notifications to a user/users on any event in your application. To send a push notification, you should use QBEvent
, fill its fields with push notification parameters (payload) and set push recipients.
You can send only FCM data messages to the Android app. QuickBlox doesn’t support FCM notification messages.
To process FCM data messages on your app when the app is in the background, you need to handle them. If not handled, they will not pop on the screen even if the app has received such push notification. See FCM documentation to learn more about data messages.
You can send APNs VoIP notifications to the iOS app. However, if the iOS app is not subscribed to APNs VoIP notifications or the APNs VoIP certificate has expired, the regular APNs will be delivered instead of APNs VoIP.
To receive push notifications, you should register the BroadcastReceiver
.
Or use the onMessageReceived()
in your class that extends QBFcmPushListenerService
.
Cause 1: incorrect FCM server key is set in the Dashboard.
Tip: check if you put a correct FCM server key into the FCM API key field in the Dashboard => YOUR_APP => Push Notifications => Settings. See how to obtain the FCM server key and where to set it here.
It is possible that you are using the FCM sender ID instead of the FCM server key in the Dashboard. Try to send the message from a Firebase console directly. If a message has appeared, a problem is in the FCM server key. If the FCM server key is incorrect, then there will be the following error: error 401 (Unauthorized, check your App auth_key)
. This means that the QuickBlox server wasn’t able to authorize on the Firebase server.
Cause 2: incorrect FCM sender ID in the google-services.json
file.
Tip: check if you added a correct google-services.json
file to your project.
Cause 3: the push is sent to the production zone while the device is subscribed to the development zone or vice versa.
Tip: check if you put the same FCM server key into the FCM API key field in the Dashboard => YOUR_APP => Push Notifications => Settings for development and production to reduce the risk of error.
Cause: a device registration token is invalid.
The device registration token is represented as token
within the system. See this section to learn how to subscribe a device to push notifications.
Tip: check if the device registration is correct. The device registration token can be invalid due to a number of reasons:
For all these cases, remove the invalid device registration token and stop using it to send messages. Then, obtain a new token and make sure to create a new subscription with a valid token.