Push Notifications (GCM) while app is running

Hi,

if I receive a GCM push notification, while the application is running, I receive the event via my notification callback. This is as expected.

Unfortunately, the specified sound is still played automatically and the notification is added to the notification bar in Android. Is there a way I can avoid this?

I am on the latest stable build 2013.1137.

Thanks in advance!

Best regards,

Martin

I’m having this problem as well. 

Did you solve this @marcar?

Not until now. I haven’t checked with the latest stable yet, but as you are experiencing the problem, I suspect the issue is still there.

This is by design.  A notification alert will always be displayed on the status bar, even if your app is in the foreground.  It behaves consistently in or out of the app, which is a behavior I personally like.  Especially if I’m doing something within an app, because I don’t want to be interrupted and I’d rather the notification be queued until I’m ready to deal with it.

If you don’t want the notification to remain in the status bar, then what you should do is remove all notifications via your notification event listener by calling the system.cancelNotification() function without any arguments.

   http://docs.coronalabs.com/daily/api/library/system/cancelNotification.html

Did not realise that system.cancelNotification() removes notifications from the status bar as well… 
Thanks Joshua! 

Ah, didn’t notice this as well. Will try, thanks for the hint!

But the problem with this is, this cancels the previously local scheduled notifications as well… 
That makes this solution more or less unusable… 

Right.  You would have to re-post your local notifications after calling that function.  But it’s your only option if this is the behavior that you want.

Ah…well. 
I guess I can make do with this for now… 
Thanks anyway. 
 

I’m having this problem as well. 

Did you solve this @marcar?

Not until now. I haven’t checked with the latest stable yet, but as you are experiencing the problem, I suspect the issue is still there.

This is by design.  A notification alert will always be displayed on the status bar, even if your app is in the foreground.  It behaves consistently in or out of the app, which is a behavior I personally like.  Especially if I’m doing something within an app, because I don’t want to be interrupted and I’d rather the notification be queued until I’m ready to deal with it.

If you don’t want the notification to remain in the status bar, then what you should do is remove all notifications via your notification event listener by calling the system.cancelNotification() function without any arguments.

   http://docs.coronalabs.com/daily/api/library/system/cancelNotification.html

Did not realise that system.cancelNotification() removes notifications from the status bar as well… 
Thanks Joshua! 

Ah, didn’t notice this as well. Will try, thanks for the hint!

But the problem with this is, this cancels the previously local scheduled notifications as well… 
That makes this solution more or less unusable… 

Right.  You would have to re-post your local notifications after calling that function.  But it’s your only option if this is the behavior that you want.

Ah…well. 
I guess I can make do with this for now… 
Thanks anyway.