0

Hi i'm trying to show Push Notifications in Android Status Bar. I'm using ibm-mfp-push plugin and this code:

onDeviceReady: function() {
        app.receivedEvent('deviceready');

          BMSClient.initialize("xxxxx","xxxxx");

        MFPPush.registerDevice({}, function(data){

            alert("Success ::" + data)
        }, function(error){
            alert("Failure ::" + error);
        }); 

        var notificationsCallback = function(notification){
            alert("Incoming notification :: " + JSON.stringify(notification))           
        };

        MFPPush.registerNotificationsCallback(notificationsCallback);

    }

I recieve notifications correctly but i have no idea how show this notifications in status bar. Any ideas?

Thank you

James Young IBM
  • 616
  • 1
  • 5
  • 13
  • By status bar, are you referring to the notification shade? If the application is in background, does the notification appear in the shade? – Vivin K May 20 '16 at 08:37
  • Yes, i'm referring to the notification shade, sorry. If the application is in background notifications are not shown. Only when application is open notifications appear in alerts. – Álvaro Domínguez López May 20 '16 at 08:44
  • When the application is in background, and you dispatch a notification, do you see anything in logcat? – Vivin K May 20 '16 at 09:09
  • Sorry. I can't use in this Logcat in this moment. I think I receive notifications correctly, but any attempt to use plugins (local notifications) for notifications appear in the notification shade have been useless. I am only able to make them appear as alerts – Álvaro Domínguez López May 20 '16 at 11:29
  • Please provide context... what is your mfp version... what is "bms"... – Idan Adar May 20 '16 at 12:58
  • Slightly confused as to what exactly you're asking for. If the application is in the foreground you will not receive a notification in your notification shade, you'll receive an alert instead. If the application is in the background when the notification is received it should show in the notification shade / status bar with a star icon (default). Is this not the case? – James Young IBM May 20 '16 at 15:44

2 Answers2

1

In case you application was running when remote notification arrived it will not be displayed automatically in notification shade since it will be immediately processed by application. You will see notification in the notification shade only incase application was not running when notification has arrived.

That said, you can add you own logic to add items to notification shade once remote notification was received. You need to add this logic in your notificationsCallback. You can use an existing local-notifications plugin (https://www.npmjs.com/package/de.appplant.cordova.plugin.local-notification) or implement it on your own with https://developer.android.com/reference/android/app/Notification.Builder.html

Anton
  • 3,166
  • 1
  • 13
  • 12
1

I already found the solution. Sorry if I was unclear on the question. My problem was that I could not get notifications appear in the notification shade.

When the application is in the foreground notifications appears to me as if javascript alert and when the application is in the background nothing appears until put in the foreground.

I tried to use various local notification plugins but when the event onDeviceReady is fullfiled these plugins are not loaded.

For those who do not know the plugin I leave some documentation: https://www.npmjs.com/package/ibm-mfp-push

The solution is to add in the onDeviceReady event this:

CDVMFPPush.setIgnoreIncomingNotifications(boolean ignore); (being ignore == true)

That function is described in documentation as:

By default, push notifications plugin handles all incoming Push Notification by tunneling them to JavaScript callback. Use this method to override the plugin's default behavior in case you want to manually handle incoming push notifications in native code.

BMSClient is a singleton that serves as an entry point to bluemix client-server communication. In my case I use it to initialize the client especifying two parameters:

BMSClient.initialize("APPROUTE","APPGUID");

Thank you for your answers. Happy to belong to this great community.

regards