3

Using this plugin in an Ionic project I have been able to get local notifications going when a GCM push arrives (using ngCordova and the appropriate plugin).

The code flows a little something like this:

Inside the scope of an abstract app controller the pushNotification is set-up with an ecb that references a global onNotification function (outside of angular scope all together) there a localNotification is added.

Inside the angular scope an onclick handler is declared to lead the user to the right view.

The problem is that when the app is not in foreground, the following unwanted behaviours can be observed:

  • The title of the notification is not displayed (even when hardcoded)
  • The desired sound does not play (the device only vibrates)
  • When the app comes to foreground, the onclick notification is not fired.

My notification code looks like this:

window.plugin.notification.local.add({
  message:    e.payload.message,
  title:      e.payload.activity.name,
  sound:      'android.resource://' + package_name + '/raw/bounce',
  json:       JSON.stringify(e.payload),
  autoCancel: true,
});

Any clues as to what is going on?


FIXED: As it turns out, the event callback is never called when the app is in the background and the push notification is turned into a local notifaction - a feature I had overlooked. Thank you all for your time and trouble :/

Hartog
  • 108
  • 7
  • Your code snippet makes me guess you didn't try a fixed string for the title property. You're sure `e.payload.activity.name` has a value? – Christiaan Westerbeek Jul 02 '14 at 06:51
  • Yes, I am sure (99%) it has a value; and yes I did try it with a hard coded value - no show when the app is not in foreground. – Hartog Jul 02 '14 at 08:45
  • 1
    Any relation to this:https://github.com/katzer/cordova-plugin-local-notifications/issues/42 ? – Vrashabh Irde Jul 08 '14 at 10:22
  • @Slartibartfast tis quite a long read; but there may be something of interest in there... Thx for pointing that out! – Hartog Jul 08 '14 at 12:16

1 Answers1

-1

Try this,

public void notifyUser(){

    NotificationManager notificationManager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent intent = new Intent(MyActivity.this, SomeActivity.class);

    //use the flag FLAG_UPDATE_CURRENT to override any notification already there
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Notification notification = new Notification(R.drawable.ic_launcher, "Some Text", System.currentTimeMillis());
    notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND;

    notification.setLatestEventInfo(this, "This is a notification Title", "Notification Text", contentIntent);
    //10 is a random number I chose to act as the id for this notification
    notificationManager.notify(10, notification);   }
lurknobserve
  • 230
  • 3
  • 13