Android - Stop (Intercept) C2DM Push Notification if app is running?

android, android-c2dm, push-notification

Solution

@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!

Problem

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!

Original source