Skip to main content


         This documentation site is for previous versions. Visit our new documentation site for current releases.      
 

This content has been archived and is no longer being updated.

Links may not function; however, this content may be relevant to outdated versions of the product.

Enabling push notifications with the Connect SDK on Android

Updated on July 18, 2018

Push notifications allow users to instantly receive important information on their mobile devices. To enable push notifications in an Android native mobile app that uses the Connect SDK, you must perform server-side configuration and make changes to the project files for the Android native mobile app.

Server-side configuration

Perform the following server-side configuration steps:

  1. Go to the Google Developer portal and generate a configuration file for your Android application that includes:
    • Sender ID - The Google Cloud Services (GCM) identifier used to authenticate the mobile app with the Android Push Notification Integration services.
    • Server API Key - A key used by the server to authenticate with the Google Cloud Messaging (GCM) services.
  2. Create a Pega 7 Platform application and do the following steps:
    1. On the Mobile tab of the Application rule form, click Custom mobile app.
    2. Create an Android certificate set that specifies the push notifications Google Server API Key and Sender ID obtained in the previous step.
      Remember that to use an Android certificate set, you must also upload a signing certificate, even though it is not used. For more information, see Configuring push notifications on Android.
    3. In the Certificate set name list, select the new Android certificate set created in the previous step.
    4. Click Save.
  3. Send push notifications by using the Push Console or by adding a push notifications shape to a workflow of your application. For more information, see Accessing the Push Console and Adding the push notifications shape to a workflow.

Procedure

Perform the following steps to enable push notifications in an Android native mobile app project that uses the Connect SDK.

  1. Open the Android Studio project for your mobile app.
  2. Create a class that extends the InterfaceNotification.NotificationHandlerProvider interface as shown in the following example.
    public class MyApplication extends Application implements Notification.NotificationHandlerProvider {
    ​
        (...)
    ​
        @Override
        public NotificationHandler getNotificationHandler() {
            return new NotificationHandler() {
              
                @Override
                public int getSmallIcon() {
                    // chceck https://developer.android.com/reference/android/app/Notification.Builder.html#setSmallIcon(int)
                    return id_of_notification_small_icon;
                }
    ​
                @Override
                public void onNotificationReceived(@NonNull Context context, @NonNull NotificationData data) {
                    // do something with received data. Methos is called right before showing notificaion. Can be ignored.
                }
    ​
                @NonNull
                @Override
                public String getNotificationChannelId() {
                    // Supporded from Android 8.0.
                    return "";
                }
    ​
                @NonNull
                @Override
                public NotificationChannel createNotificationChannel(@NonNull Context context) {
                    // Optional. Supporded from Android 8.0.
                    // Allow to create custom NotificationChannel. Channel must have the same id as result of getNotificationChannelId() method.
                    // check: https://developer.android.com/reference/android/app/NotificationChannel
                    return 
                }
    ​
                @Nullable
                @Override
                public PendingIntent createNotificationContentIntent(@NonNull Context context, @NonNull NotificationData notificationData) {
                    // create and return PendingIntent to customize notification clicking event. Return null to ignore notification clicking.
                    // check: https://developer.android.com/reference/android/app/Notification.Builder#setContentIntent(android.app.PendingIntent)
                    return null;
                }
    ​
                @NonNull
                @Override
                public android.app.Notification buildNotification(@NonNull Context context, @NonNull NotificationData data) {
                    // Override creating notification that will be shown.
                    return notification;
                }
            };
        }
    }
    
  3. In the Activity class, enable notifications by adding the following synchronous or asynchronous code using the previously generated Sender ID that was obtained from the server-side configuration in step 1. You call the enable() method after you have successfully authenticated to the Pega Platform application.
    Synchronous call:
    try{
      pegaApi.notification().register(, context.getString(R.string.gcm_defaultSenderId));
    ​} catch (NotificationException e) {
                    // error occured
    ​}
    ​// registration completed
    Asynchronous call:
    ​pegaApi.notification().register(, context.getString(R.string.gcm_defaultSenderId), new Notification.NotificationRegisterCallback() {
      @Override
      void onSuccess(){
                    // registration completed
      }
      
      @Override
      void onFailure(NotificationException e) {
                    // error occured
      }
    ​});
    By calling this method in your project for the mobile app, push notifications are enabled using the Notification.NotificationRegisterCallback() method.

Tags

Pega Platform 7.3.1 Pega Mobile Mashup Mobile Pega Express Communications and Media Consumer Services Financial Services Government Healthcare and Life Sciences Insurance Healthcare and Life Sciences Manufacturing Consumer Services Consumer Services

Have a question? Get answers now.

Visit the Support Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega.com is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us