- Offline messages. Send a chat message when a recipient is offline. In this case, a push notification will be sent automatically if the user is offline.
- Offline calls. Make a video/audio call with offline opponents. In this case, a push notification will be sent manually.
- Requests to contact list. Send requests to add a user to the contact list. In this case, a push notification will be sent manually).
- User tags. Send notifications to specific user groups defined by tags.
Before you begin
- Register a QuickBlox account. This is a matter of a few minutes and you will be able to use this account to build your apps.
- Configure QuickBlox SDK for your app. Check out Setup page for more details.
- Create a user session to be able to use QuickBlox functionality. See Authentication page to learn how to do it.
HTTP v1 API
HTTP v1 API
1. Generate a new service account key

- Open the Firebase console and select your project.
- Go to Project settings > Service Accounts.
- Click on Generate new private key and confirm by clicking Generate key.
- Securely store the JSON file containing the private key that will be downloaded
2. Navigate to the push notifications section on QuickBlox dashboard

- Head over to QuickBlox dashboard, and choose your application.
- Select the push notifications tab and navigate to the settings page.
- Select the Service account key tab
3. Upload the service account key on QuickBlox dashboard

- Choose the environment for your service account key. (Development/Production)
- Click on the browse button and select the JSON file containing the key that was downloaded in step-1.
- Hit the upload button.
How to enable Cloud Messaging API (Legacy)
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:



- Click on the Settings icon.
- Select Project Settings from the drop-down list.

- In section Project Settings select Cloud Messaging tab.
- Click on the three-dots (kebab) menu to the right of Cloud Messaging API (Legacy) and choose the Manage API in Google Cloud Console option. You will be redirected to Google Cloud Console.

- Click the Enable buttons in the Cloud Messaging section.

- Refresh the Cloud Messaging page and a server key will appear.

Configure Firebase project and API key
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.- To find your FCM server key, go to your Firebase console => Project Settings => Cloud Messaging.


- Copy the server key to your Dashboard => YOUR_APP => Push Notifications => Settings, select the environment for which you are adding the key and click the Save key. Use the same server key for development and production zones. You can use both these environments up to you.

Add Firebase to your Project
- As part of enabling Firebase services in your Android application, you need to add the google-services dependency to your project-level
build.gradlefile.
Groovy
- Add FCM dependency to your app level
build.gradlefile.
Groovy
- Include a gms plugin to your app level
build.gradlefile.
Groovy
- Download the
google-services.jsonfile from your Firebase Project dashboard and put it into your app folder in your Android project. - Copy the sender ID value following Firebase console => Project Settings => Cloud Messaging.


- Edit your app AndroidManifest file and add your Firebase sender ID as well as notification type and environment to integrate automatic push subscription.
XML
com.quickblox.messages.TYPE- can beGCMorFCM.com.quickblox.messages.SENDER_ID- your sender ID from google console (for example, 639872757929).com.quickblox.messages.QB_ENVIRONMENT- can beDEVELOPMENTorPRODUCTION.
- Then you need to setup
QBFcmPushListenerServiceandQBFcmPushInstanceIDServicein AndroidManifest.
XML
Automatic push subscription
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.Enable/Disable push subscription
Here you can use a global setting to enable or disable delivery of push notifications. Set this parameter only once.- Java
- Kotlin
Track subscription status
To be aware of what is happening with your push subscription, whether you’re subscribed successfully or not, you can use theQBSubscribeListener. Just add QBSubscribeListener right after the QBSettings.getInstance().init() code.
- Java
- Kotlin
Manual push subscription
If you do not want to use the automatic push subscription feature, then do the following:- Set
SubscribePushStrategy.NEVERas the main strategy.
- Java
- Kotlin
- Java
- Kotlin
- And then in your class extended from
QBFcmPushListenerServiceyou need to handle when the token is refreshed:
- Java
- Kotlin
- Add your class extended from
QBFcmPushListenerServiceto the Manifest file.
XML
Send push notifications
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 useQBEvent, fill its fields with push notification parameters (payload) and set push recipients.
- Java
- Kotlin
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.
Receive push notifications
To receive push notifications, you should register theBroadcastReceiver.
- Java
- Kotlin
onMessageReceived() in your class that extends QBFcmPushListenerService.
- Java
- Kotlin
Troubleshooting
Push notifications are not received on Android devices
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.
Cause 3: the push is sent to the production zone while the device is subscribed to the development zone or vice versa.
A subscription is removed after a push is sent and the push isn’t delivered
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.- Some other data is set instead of a correct device registration token. For example, a Firebase project ID, Firebase user token, etc.
- The client app unregistered itself from GCM/FCM. This can happen if the user uninstalls the application or, on iOS, if the APNs Feedback Service reported the APNs token as invalid.
- The registration token expired. For example, Google might decide to refresh registration tokens or the APNs token may have expired for iOS devices.
- The client app was updated, but the new version is not configured to receive messages.