Push Notifications provide a way to deliver some information to user while he is not using your app actively.
The following use cases can be covered additionally with push notifications:
send a chat message if recipient is offline (a push notification will be send automatically)
make a video call with offline opponents (need to send a push notification manually)
request to add a user to contact list (need to send a push notification manually)
Configure Firebase project and Service account key (recommended)
In order to start working with push notifications functionality you need to configure it.
Create and configure your Firebase project and obtain the Service account key. If you have any difficulties with Firebase project registration, follow our guide.
To find your FCM service account key go to your Firebase console > Cloud Messaging > Manage Service Accounts section:
Select and configure Manage Keys option:
Select ADD KEY, Create new key:
Select Key type (json recommended) and create:
Save it locally:
Browse your saved FCM Service account key in your Dashboard > Your App > Push Notifications > Credentials, select the environment for which you are adding the key. Use the same key for development and production zones.
Configure Firebase project and Server key (DEPRECATED)
Create and configure your Firebase project and obtain the Server key. If you have any difficulties with Firebase project registration, follow our guide.
To find your FCM server key go to your Firebase console > Cloud Messaging section:
Copy your FCM server key to your Dashboard > Your App > Push Notifications > Credentials, select the environment for which you are adding the key and hit Save key. Use the same key for development and production zones.
Prepare app dependencies
1. As part of enabling Firebase services in your Android application you need to add the google-services plugin to your Project build.gradle file:
!> If you use google play services in your project, use version 11.8.0 or higher (version we use in our SDK) as all com.google.android.gms libraries must use the exact same version specification.
If you use version higher than 11.8.0, then just add explicit dependency:
2. Include gms plugin in the bottom of your module build.gradle :
3. For GCM push type add an empty current_key settings into your google-services.json file for your package name (this paragraph relates to GCM. If you use FCM and already have some value in current_key field, leave it as is):
Prepare app AndroidManifest (only v1)
Copy Sender ID value from your Firebase console:
Edit your app AndroidManifest.xml file and add your Firebase Sender ID as well as notification type and environment there:
To integrate automatic push subscription you just need set values in AndroidManifest:
com.connectycube.pushnotifications.TYPE - can be FCM
com.connectycube.pushnotifications.SENDER_ID - your sender id from google console (for ex.8617520217632)
com.connectycube.pushnotifications.ENVIRONMENT - can be DEVELOPMENT or PRODUCTION
Then you need to setup FcmPushListenerService and FcmPushInstanceIDService:
Automatic push subscription (only v1)
ConnectyCube Android SDK provides automatic push subscription management. It means you don’t need 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.
Here are the requirements on how to integrate automatic push subscription feature to your app:
Enable/Disable push subscription
Here you can use global setting to enable or disable delivery of push notifications (means to set this parameter only one time):
To be aware about what is happening with your push subscription, whether you’re subscribed successfully or not, you can use the SubscribeListener. Just add SubscribeListener right after the ConnectycubeSettings.getInstance().init() code:
You can manually initiate sending of push notifications to user/users on any event in your application. To do so you need to form a push notification parameters (payload) and set the push recipients: