4

I have implemented C2DM (Android Push Notification) to my app and all is working fine. However, when my app is running, I am able to get notifications. May I know how if I am able to stop the push notification from coming in if my application is running? I only want to receive push notifications only when my app is not running. Because as far as I know, the APNS (Apple Push Notification Service) would check if the app is running or not before sending the push notification. Does C2DM do this too?

Thanks all in advance!

user1321096
  • 143
  • 3
  • 14

2 Answers2

4

@Moujib is right. I am facing the same problem as you, I'd like to stop the push notifications if the app is running. I did managed to solve the problem by using the code from here: http://kpbird.blogspot.com/2011/08/android-check-application-is-running.html

Use that piece of code to check if your app is running or not. Then, if the app is running, I did nothing to it, if it is not running, I would then send/get the push notifications. Hope that helps!

Winona
  • 2,950
  • 2
  • 21
  • 29
2

Well you can disable your notifications when the app is running , in other words , push messages will still get to you but you have the control to make a notification or not .

If app is running or in foreground no notifications else Notify ...

moujib
  • 742
  • 2
  • 7
  • 26
  • Thanks for your response, @moujib. But how can I check if the app is running/in foreground? – user1321096 May 16 '12 at 07:41
  • 1
    Easy here we are : stackoverflow.com/questions/3667022/android-is-application-running-in-background/5862048#5862048 – moujib May 16 '12 at 07:47
  • Thanks! But is it possible to check if the app is running in the c2dm receiver class? – user1321096 May 16 '12 at 07:50
  • Yes I think it's doable , give it a try and see if you can pop a log when you receive a push notification while your app is in foreground on your onMessage callback – moujib May 16 '12 at 08:03
  • Hi, I still have no idea how I can stop the notification from popping in if I am still in the app. Can you please guide me? I am quite lost. – user1321096 May 16 '12 at 09:16