Push Notifications

Direct Push Notifications

With this solution, the notifications will be triggered and delivered to your users directly by Amity's servers. There's nothing that the Android client has to do in order to display the notification to your users. Amity's servers will prepare for you a notification that can be directly displayed to the user as and when it's received.

Setup Push Notification Certificate.

In order for Amity's server to start sending push notifications to the Android client, you need to prepare the Firebase certification (for the device that support by google push notification service) or Baidu cloud Push certification(for the device not support by google service) and upload to Amity system via Amity Admin panel.

Push Notification Triggers

A new push notification will be sent to a specific user when the following event happens IN a community where the user is a member.
  • A new post has been created in the community user is a member.
  • Post owner has been reacted by a user in the community
  • Post owner has new Comment created by a user in the community.
  • Comment or Reply owner has been reacted by a user in the community
  • Comment owner has a new Reply created by a user in the community.

Push Notification Examples

As Amity's servers are responsible for choosing the content of the push notification, you can expect your users to receive the following notifications for different kinds of events:
  • A new post has been created in the community user is a member.
Title : CommunityDisplayname
Body : userDisplayname created new post in your community.
  • Post owner has been reacted by a user in the community
Title : CommunityDisplayname
Body : userDisplayname reacted to your post
  • Post owner has new Comment created by a user in the community.
Title : CommunityDisplayname
Body : userDisplayname commented to your post
  • Comment or Reply owner has been reacted by a user in the community
Title : CommunityDisplayname
Body : userDisplayname reacted to your comment
  • Comment owner has a new Reply created by a user in the community.
Title : CommunityDisplayname
Body : userDisplayname replied to your comment

Push Notification context customization

as default, all the event related to the Community feature has default context base on each event trigger, to customize the context for each event, you can access to Admin panel to do so.

Client Push Notification Toggles

The SDK has three levels of notifications and in order for it to be sent, a notification has to pass throughout all three levels.
  • Network Level: (via Admin Panel) turning off notifications at this level effectively disable push notifications altogether for all of your customers.
  • User Level: (via client) A user can choose to enable/disable the notifications that it receives on the device (this is an absolute option: enable all or disable all). Please note that this setting is per user, not per device: regardless of which device sets this toggle, the new preference will take effect in all the devices where the user is logged in.
  • Community Level: (via client) A user can choose to enable/disable notifications for a specific community (where the user is a member of). Again, this preference is per user, not per device.
If the Network level has been disabled, the event in the User level AND Community level will be disabled as well.

Client Registration

The first step of receiving the Push notification start with:

Initialize Push Notification

FCM dependency:
implementation 'com.github.AmityCo.Amity-Social-Cloud-SDK-Android:amity-push-fcm:x.y.z'
Before you can start receiving push notifications, you need to obtain a FCM unique token string that identifies each FCM client app instance:
You can initialize the services with the obtained token. Please note that the FCM token can be changed throughout the application life cycle. Please make sure that the FCM token supplied to the messaging SDK is up to date. To notify the messaging SDK of the latest token, the following line of code can be called whenever necessary:

Retrieve Push Notifications

To retrieve push notifications, use a service that extends FirebaseMessagingService. Refer to Firebase's messages handling documentation for the detailed information.

Push Notification In China

Since Google play services are banned in China, The messaging SDK provides Baidu push services as a substitute for FCM. The messaging SDK requires an API key and a secret key from Baidu:
Baidu dependency:
implementation 'com.github.AmityCo.Amity-Social-Cloud-SDK-Android:amity-push-baidu:x.y.z'
Note: Baidu push services require a number of additional permissions. You can find a list of permissions here.
Baidu API key is needed for Baidu push services initialization:
Note: The messaging SDK always considers FCM as a primary push provider and Baidu as a secondary push provider. If the messaging SDK detects Google play services on the device, Baidu push services won't be initialized.

Registration

The registration will automatically pick up the active userId, and Amity's back-end will start sending push notifications to the particular user. In the event where the active userId has been changed, registration will be required again.
Registering your app for push notification will require a registered ASCClient instance (necessary to know which user is associated with this device) and a push notification token.
Amity's Development Kit does not manage:
  • user-facing requests for push notifications and authorizations
  • the creation and refreshing of push notification tokens
It's up to your app to take those steps and pass the notification token to the SDK.
// Registration
AmityCoreClient.registerDeviceForPushNotification().subscribe()
We recommend you to observe the completion block outcome to ensure a successful registration.
If the device was previously registered with this or another user, the previous registration is invalidated as soon as this new request is received, which means that the device will always receive notifications of up to one user.

Community Level Push Notification Toggle

Setting Community Push Notifications

For community preferences we use the AmityCommunityRepository, obtained via an instance of AmityCommunityRepository :

Getting Community Push Notifications

Client Unregistration

Unlike the registration, unregistering for push does not require the AmityCoreClient instance to be associated with any user, therefore you can unregister the device from receiving push notifications as soon as the AmityCoreClient has been initial

User Level Push Notification Toggle

Setting User Push Notifications

For user preferences we use the AmityCoreClient, obtained via an instance of AmityCoreClient :

User Push Notifications

Client Unregistration

Unlike the registration, unregistering for push does not require the AmityCoreClient instance to be associated with any user, therefore you can unregister the device from receiving push notifications as soon as the AmityCoreClient has been initial
Export as PDF
Copy link
Outline
Direct Push Notifications
Setup Push Notification Certificate.
Push Notification Triggers
Push Notification Examples
Push Notification context customization
Client Push Notification Toggles
Client Registration
Initialize Push Notification
Retrieve Push Notifications
Push Notification In China
Registration
Community Level Push Notification Toggle
Setting Community Push Notifications
Getting Community Push Notifications
Client Unregistration
User Level Push Notification Toggle
Setting User Push Notifications
User Push Notifications
Client Unregistration