Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to debug the app on receiving push notification using GCM?

Initially my app is closed and when I receive a new message from GCM push service, I am starting a new activity from onMessage() in my class which extends GCMIntentService. I want to use the debugger to check some errors. My question is that is there a way to Debug the app when started from the Push Notification?

To clear a bit more, I have a BroadcastReceiver and a service attached to it. Even is the app is closed, it receives the broadcast and starts an activity based on the message received. It is possible that the app receives the broadcast when it is not open. Now, when the app is open and I get a Push Message then I can debug it. But the problem is when when app is closed and it receives the broadcast, then how to debug it?

like image 898
Shobhit Puri Avatar asked Jul 11 '13 22:07

Shobhit Puri


People also ask

How does GCM push notification work?

The first step in GCM is that a third-party server (such as an email server) sends a request to Google's GCM server. This server then sends the message to your device, through that open connection. The Android system looks at the message to determine which app it's for, and starts that app.

Can push notifications be tested on emulator?

If your target platform is Android, you can test a push notification on an emulator if the emulator target uses a version of Google APIs to receive the push notifications.

How do apps receive push notifications?

The app publisher composes a manual message through a message composer user interface. Alternatively, the publisher sets up an automated message to be sent via the API. The publisher defines the audience to whom the push notification will be sent.


1 Answers

@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{
    /*
      the following line will halt the app here
      to give you time to attach the debugger
    */
    android.os.Debug.waitForDebugger();

    /*
      then you can put a breakpoint on any line
      after that, like here:
    */
    Log.d("onMessageReceived", "From: " + remoteMessage.getFrom());

    ...
}

You can put the line android.os.Debug.waitForDebugger(); anywhere in your code where you want to stop execution and attach the debugger. Just remember to remove it when you're done debugging.

like image 104
Wex Avatar answered Sep 17 '22 19:09

Wex