3

I've recently added GCM messaging to my app using google's helper classes (GCMBroadcastReceiver, GCMBaseIntentService). It works beautifully when the app is running, both when it's in the foreground and when it's not. However, when it's not running, nothing works.

As a test, I extended GCMBroadcastReceiver and added log statements to getGCMIntentServiceClassName() and peekService(). When the app is running and a message arrives I see the former called. The OS then instantiates my service class, which eventually results in onMessage() being called.

When the app isn't running getGCMIntentServiceClassName() never gets called.

My manifest is pretty much the boiler-plate code from Google's GCM examples.

Is there an extra permission or flag I need to set in order for the OS to wake up my app when it's not running and a message arrives w/ the correct intent category? My receiver is defined as:

<receiver
    android:name=".GCMBroadcastReceiver"
    android:permission="com.google.android.c2dm.permission.SEND" >
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

        <category android:name="PACKAGENAME" />
    </intent-filter>
</receiver>

Bear in mind: this works when the app is running in the background.

jph
  • 2,181
  • 3
  • 30
  • 55

2 Answers2

6

Bleh. Figured it out. David Wasser's answer here:

BroadcastReceiver isn't working

explains why I'm not seeing the broadcasts when my app isn't running. I was force quitting it from Manage Applications, which puts it into the "stopped" state (and thereby causes the system to exclude it from broadcasts by default).

When I install the app, launch it, power down the device, then power it on again, I'm receiving the broadcasts properly.

Community
  • 1
  • 1
jph
  • 2,181
  • 3
  • 30
  • 55
  • Thanks.... yeah I was also killing it and it would not start the application again. After Power Resets... the application is NOT seen in Task Manager and then a GCM message does start the application. – lepert Sep 30 '13 at 23:12
0

I had same issue and fixed by just running the through RUN button from Android Studio.

I think in Debug Mode it doesn't work

For Guru
  • 1,197
  • 13
  • 23