Skip to main content

Push Notification for Andriod MAF application via MCS

Part 1 : Configure MCS Backend with Google Project ID

Step #1: Register yourself for Google Cloud Messaging :

There are several tutorials available online to guide you to do this. Some examples :

Once you have registered there are 4 things which are important and will be used in later part of this blog :
Project Number
Browser API Key
Make sure the "Google Cloud Messaging for Android" is enabled for this Project. 

Step #2 : Configure MCS backend with the Step#1 details

Create an Mobile Backend. Then go to your Mobile Backend Settings page. There will be a default Client Application created for you. Click on Edit and do the following.

In the above picture

Application Name and ID = Google Project Name
API Key = Google Browser API Key
Sender ID = Google Project Number

Now your backend is configured and ready to send Push Notifications.
Next step is to configure your MAF application.

Part 2 : MAF application 

For a mobile app to receive push notification, the mobile app should "register" itself with MCS backend first. This is an one time activity. As a developer/designer you need to find a right component to call the register URI. I tried to do this inside LifeCycleListenerImpl, but it didn't work, so I moved it to my datacontrol class and made sure it is being called only once.
This registration process will intern register your app with Google Messaging Service.

Below are the important steps and code snippets for the MAF application.
1. Create a simple MAF application.
2. Create a PushNotificationListener class inside ApplicationController project.

import oracle.adfmf.framework.event.EventListener;

public class PushNotificationListener implements EventListener {
    public final static String PUSH_MESSAGE             =   "#{applicationScope.push_message}";
    public final static String MCS_REGISTRATION_STRING  =   "#{applicationScope.mcsregistrationString}";
    public final static String PUSH_ERROR               =   "#{applicationScope.push_errorMessage}";
    public final static String PUSH_DEVICE_TOKEN         =   "#{applicationScope.deviceToken}";  
    public PushNotificationListener() {

    public void onOpen(String token) {
        // Clear error in app scope
        AdfmfJavaUtilities.setELValue(PUSH_ERROR, null);       
        // Write the token into app scope       

    public void onMessage(Event event) {
        String msg = event.getPayload();               
        //set push message to application scope memory attribute for
        //display in the view.
        AdfmfJavaUtilities.setELValue(PUSH_MESSAGE, msg); 

    public void onError(AdfException adfException) {
        Utility.ApplicationLogger.logp(Level.WARNING, this.getClass().getSimpleName(), "PushHandler::onError",
                                       "Message = " + adfException.getMessage() + "\nSeverity = " +
                                       adfException.getSeverity() + "\nType = " + adfException.getType());
        AdfmfJavaUtilities.setELValue(PUSH_ERROR, adfException.toString());

3. Edit LifeCycleListenerImpl to implement PushNotificationConfig interface. This will require you to override 2 methods. You also need to update start() method of this class.

  public void start()  {
    Utility.ApplicationLogger.logp(Level.FINE, this.getClass().getSimpleName(), "LifeCycleListener::start()","Push is enabled for application");         
    EventSource evtSource = EventSourceFactory.getEventSource(EventSourceFactory.NATIVE_PUSH_NOTIFICATION_REMOTE_EVENT_SOURCE_NAME);
    evtSource.addListener(new PushNotificationListener());    

    public long getNotificationStyle() {
        return PushNotificationConfig.NOTIFICATION_STYLE_ALERT | PushNotificationConfig.NOTIFICATION_STYLE_BADGE | PushNotificationConfig.NOTIFICATION_STYLE_SOUND;

    public String getSourceAuthorizationId() {       
        String senderId = "<GOOGLE_PROJECT_ID>"; //
Google Project Number        ValueExpression ve = AdfmfJavaUtilities.getValueExpression("#{applicationScope.applicationId}", String.class);
        ve.setValue(AdfmfJavaUtilities.getAdfELContext(), senderId);
        return senderId;

4.  Code snippets to register your app with MCS. (You also need to create a dummy REST connection)

// Step 1 : connect to MCS backend
        String mobileBackendUrl = "<URL_MCS>";
<NAME_OF_DUMMY_CONN>", "restconnection", "url", mobileBackendUrl);
        String mobileBackendId =  "<MCS_BACKEND_ID>";
        String mbeAnonymousKey =  "<MBE_ANONYMOUS_KEY>";
        String appKey =    "<APP_KEY_FROM_MCS>";

        MBEConfiguration mbeConfiguration = new MBEConfiguration("
<NAME_OF_DUMMY_CONN>", mobileBackendId, mbeAnonymousKey, appKey,


        MBE mobileBackend = MBEManager.getManager().createOrRenewMobileBackend(mobileBackendId, mbeConfiguration);
        mobileBackend.getMbeConfiguration().getLogger().logFine("Anonymous authentication invoked from DC", this.getClass().getSimpleName(), "anonymousLogin"); 

// Step 2 : login to MCS backend
        Authorization authorization = mobileBackend.getAuthorizationProvider();
        try {
        } catch (ServiceProxyException e) {           
                Utility.ApplicationLogger.log(Level.SEVERE, e.getMessage());

// Step 3 : configure MBE with device id
        String _token = (String) AdfmfJavaUtilities.getELValue("#{applicationScope.deviceToken}");
        String packageName = "<GOOGLE_PROJECT_NAME>"; //

// Step 4 : call register in a thread
        Runnable mcsJob = new Runnable(){

          public void run(){                                              
             try {
                 Notifications notification = mobileBackend.getServiceProxyNotifications();
                 String registrationInfo = notification.registerDeviceToMCS();
                 AdfmfJavaUtilities.setELValue("#{applicationScope.mcsregistrationString}", registrationInfo);
               } catch (ServiceProxyException e) {
                     Utility.ApplicationLogger.log(Level.SEVERE, e.getMessage());
              //ensure main thread is synchronized with result
        ExecutorService executor = Executors.newFixedThreadPool(2);

5. Make sure the above code snippet gets called while you open the app for the first time. What I did was. created a simple app with 1 feature, with a taskFlow. Taskflow does a method call which executes the above snippet and then opens a simple AMX page. 

Part 3 : Send a Push Notification using JQuery

I have used a simple HTML page to test my push notification setup. But you can also test your setup from MCS itself. (In Mobile Backend > Notifications)

In my HTML I have button which call the below function to send a pre-defined message.

In below javascript :
ENCODED_USER_NAME_AND_PASSWORD : is the encoded user name and password in base64. I used to encode. Your encode string should be: username:password, i.e., xyz:abc. If xyz is your username and abc is your password to login to MCS.

    function SendPushNotification() {
    var dataInput = {
        "message": "Test Message",
        url: "<URL_OF_MCS>/mobile/system/notifications/notifications",
                'Authorization' : 'Basic <ENCODED_USER_NAME_AND_PASSWORD>',
                'oracle-mobile-backend-id' : '<MCS_BACKEND_ID>'
        method: "POST",
        contentType: "application/json; charset=UTF-8",
        dataType: "json",
        data: JSON.stringify(dataInput),
        processData: true,
        error: function (xhr) {
            alert("error: " + xhr);

Acknowledgements :
Special Thanks for Arjan Kramer(@arjankramer) for the contribution on JQuery part. 
Many thanks to Frank Nimphius (@fnimphiu) for MCSSampleAndUtilities.


  1. Is this above example for Oracle MCS and Oracle MAF?Would you know if Oracle provides any demo access to MCS?

    1. Hi Deepika,

      Oracle does provide demo access to MCS for partners. You need to ask your Oracle contact for more details, it may vary country to country and partner to partner.
      Hope this helps.

      - Soham


  2. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
    mbe oracle Partner


  3. Thankyou for wonderful article. It has more Information in Your Website
    SAP Simple Logistics Online Access

  4. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
    sap corporate social responsibility services
    sap csr services in north america

  5. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
    MBE Oracle Reseller
    SAS and SAP implementation services


Post a Comment

Popular posts from this blog

Secure your Node/Express REST APIs using Passport JS

Recently I have been involved in various discussions on how to make the REST APIs as secure as SOAP.
First of all, let me start with a very basic statement, about security, it doesn't depend on your Webservice type, be it REST or SOAP, your design decisions depicts whether they can be made secure or not.
In this example blog, I will use "Micro CRUD services for Oracle Database Cloud" APIs and implement (read attach) Passport's "local" authentication strategy, to make them secure.

Code in Github : LeasifyAPIs with Passport

What is Passport JS? (from Documentation)

Passport is authentication middleware for Node. It is designed to serve a singular purpose: authenticate requests. When writing modules, encapsulation is a virtue, so Passport delegates all other functionality to the application. This separation of concerns keeps code clean and maintainable, and makes Passport extremely easy to integrate into an application.

What are "strategies" in P…

ADF Utility : Find UIComponent from Managed Bean

Many a times, it is required to find an UIComponent from ADF managed bean, to do something with it, for example : change the value of an af:outputText, change readOnly property of an af:inputText etc.

private UIComponent getUIComponent(String id) { 

        FacesContext facesCtx = FacesContext.getCurrentInstance(); 
        return findComponent(facesCtx.getViewRoot(), id);

    private UIComponent findComponent(UIComponent base, String id) {

        if (id.equals(base.getId())) {
            return base;

        UIComponent children = null;
        UIComponent result = null;
        Iterator childrens = base.getFacetsAndChildren();
        while (childrens.hasNext() && (result == null)) {
            children = (UIComponent);
            if (id.equals(children.getId())) {
                result = children;
            result = findComponent(children, id);
            if (result != null) {

Chatbots and Oracle Cloud Services

Thanks to Oracle A-Team, I had a chance to work with Chatbots.
3 pure NodeJS applications, on couple of Oracle Cloud platforms and Facebook messenger, and my chatbot was running.

Let me explain, the architecture a bit. To start with, following is the simple representation of how it works.