Push Notifications - Quick Look
Push Notifications
Push notifications allow apps to receive messages even when the app is not currently active. These notifications are typically used to deliver alerts to the app user, allowing the app designer a convenient and compelling way to deliver engagement. In the playPORTAL environment,
- Sending push notifications Push notifications can be sent by:
- the management console (either to a single or multiple app users)
- app users
In both cases, the notification received will appear the same, just the source will be different.
- Receiving push notifications Configuration is required to enable receipt of push notifications, much of this is handled by the playPORTAL SDK.
Configuration / Setup
The following steps must be performed to enable push notifications:
- Recommended: Go through the tutorial steps for adding Firebase to Android app ("Get started by adding Firebase to your app")
- Register your app with push notifications enabled via the Google Developer console.
- Download the FCM key (Project Settings -> Cloud Messaging -> Server key)
- Download the google-services.json file from the portal.
- Upload the FCM key into the playPORTAL studio portal under the app definition screen.
- Add the google-services.json into your project's "app" directory (i.e. at the same level as your app src directory).
- Add the following statement at the end of your app 'build.gradle' file:
apply plugin: 'com.google.gms.google-services'
Note: Depending on your app implementation, you will likely need a JSON converter package. Google's Gson is a solid package as is Jackson's package; the primary choice dependent on whether you prefer auto marshaling of JSONObject to/from POJO (use Jackson), or an a less POJO centric approach (use Gson).
Your app level build.gradle will then need to contain something like:
dependencies {
...
implementation 'com.google.code.gson:gson:2.8.4'
and/or
implementation 'com.fasterxml.jackson.core:jackson-core:2.9.5'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.5'
...
}
Configuring, Sending and Receiving Push Notifications
In order to bind push notifications to your app, push notifications must be enabled by invoking the following method:
public void enablePushNotifications();
Receipt of push notifications can then begin, i.e. the playPORTAL studio console, and users of your app can send notifications to other users of your app.
In order to send a notification to another user:
public void sendPushNotification(String msg, String receiverId, _CallbackFunction._GenericWithError cb);
where:
msg - String to be sent to remote user
receiverId - id of user to target with the push (id can be gotten from friends list as friend.getUserId())
cb - fnx to receive status of push notification, with invocation (Boolean status, String error) -> {}
Last modified 4yr ago