Skip to Content

Send Notifications to Your Android Application

Add foreground and background notifications to your application using Google Firebase.
You will learn
  • How to configure SAP BTP for push
  • How to configure Mobile Services for push
  • Foreground notifications
  • Background notifications
flyingfish162Bruce MengApril 26, 2024
Created by
sandeep-tds
January 9, 2023
Contributors
sandeep-tds
flyingfish162

Prerequisites

  • Step 1
    1. Go to SAP Mobile Services Cockpit, select the com.sap.wizapp application.

      Application page in CF cockpit
    2. Select Mobile Push Notification.

      Mobile Push Notification

      If you don’t see the option, follow the screenshots to add this feature:

      • Add assigned features
      • Add push notification
      • Confirm save
    3. The Mobile Push Notification screen requires information from Firebase.

      Push notification
    4. In the Firebase console, select project Wiz App, and then go to Project settings.

      • Firebase console page
      • Project settings
    5. Select the Service accounts tab and click Generate new private key button. Then click Generate key in the pop-up window and store the downloaded private key file securely because the key cannot be recovered if lost.

      Generate private key
    6. In the SAP Mobile Services Mobile Push Notification settings screen, click Browse… to load the downloaded private key file. After that, click Save to save changes.

      Push notification android

    In the cockpit, which properties are needed to enable Android push messaging in the Push Notification tab?

  • Step 2
    1. Switch to Push Registrations on the Mobile Push Notification settings page.

      Push registrations page
    2. Select certain registration to send notifications.

      Send notification

      It may be difficult to tell which registration to choose. The last field on the page shows the last time a given registration made a request. If you are unsure which registration to choose, navigate through a few screens in the application and then press the GO button to refresh the display, or select all of them and send a greeting to all the registrations.

      If you don’t see the Send Notifications button, try logging out and back into the management cockpit.

    3. Specify the notification text to send to the app.

      Send notification
  • Step 3

    Notice that the notification displayed at the top of the screen.

    Notification pop up

    Tap the notification and you can see the app displays the notification.

    Receive notification
  • Step 4
    1. On an emulator or mobile device, open another app, such as Chrome, which will cause the Wiz App to no longer be the foreground app.

    2. If you now send another notification, you will notice that because the app is in the background, or not running, a notification is placed in the notification drawer.

      Receive Notification Background
    3. Tapping the notification will bring the app to the foreground or open the app.

      Receive Notification from Background

      If the app was not running when the notification was tapped, due to a change made in the previous tutorial, you can view it by pressing Back and navigating from the Categories screen to the Entity list screen.

    Currently, the message is displayed in a dialog with cancel action.

    You can add custom logic to the app to decide on the action to take, such as displaying the new Office Furniture category.

    Show Notification Code

    For further information on push, see Push Notifications, Push API Notification Scenarios, and About FCM Messages.

    Congratulations! You have seen how an app can make use of foreground and background notifications.


Back to top