GCM client works on 4.1, not on anything else

2,798 views
Skip to first unread message

Mark Murphy

unread,
Aug 13, 2012, 8:00:18 PM8/13/12
to andro...@googlegroups.com
I have a GCM sample client app:

https://github.com/commonsguy/cw-omnibus/tree/master/Push/GCMClient

It works fine on a Nexus S running 4.1, and on an emulator running
4.1. However, on a 4.0.3 emulator, on a 4.0.3 HTC One S, and on a
2.3.6 Nexus One, I get the "Registering app" message in LogCat from
GCMRegistrar, but then nothing. All three of the environments that are
failing have a Google account registered, so that should not be my
problem.

Any ideas where I might be going wrong?

Thanks!

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 4.0 Available!

Catalin Morosan

unread,
Aug 14, 2012, 2:41:39 AM8/14/12
to andro...@googlegroups.com
One problem I see is that in your manifest you use the wrong category for the GCMBroadcastReceiver. 

The category name should be your package name. It should be <category android:name="com.commonsware.android.gcm.client"/>

Mark Murphy

unread,
Aug 14, 2012, 7:11:06 AM8/14/12
to andro...@googlegroups.com
On Tue, Aug 14, 2012 at 2:41 AM, Catalin Morosan
<catalin...@gmail.com> wrote:
> One problem I see is that in your manifest you use the wrong category for
> the GCMBroadcastReceiver.
>
> The category name should be your package name. It should be <category
> android:name="com.commonsware.android.gcm.client"/>

Thanks for catching that -- it was a copy/paste error. However, fixing
that did not change the behavior. It still works on 4.1 and still
fails in the same way on older versions.

I added a couple of tablets to the mix with the same results: Nexus 7
(4.1) works, Galaxy Tab 2 (4.0) does not.

premkumar

unread,
Aug 14, 2012, 8:27:31 AM8/14/12
to andro...@googlegroups.com
i am new to android. can any one send me the basic tutorials..

martianoo

unread,
Aug 14, 2012, 12:31:48 PM8/14/12
to andro...@googlegroups.com
Hi mark,
i think you can also override onRecoverableError method of the GCMIntentService class. It can help debug a little further.

Mark Murphy

unread,
Aug 14, 2012, 2:56:43 PM8/14/12
to andro...@googlegroups.com
On Tue, Aug 14, 2012 at 12:31 PM, martianoo <myphi...@gmail.com> wrote:
> i think you can also override onRecoverableError method of the
> GCMIntentService class. It can help debug a little further.

Thanks! In this case, it would not appear to be a recoverable error,
as onRecoverableError() is not being called.

J.Carlos Navea

unread,
Aug 14, 2012, 3:59:41 PM8/14/12
to andro...@googlegroups.com
Hi Mark,

It appears the BroadcastReceiver isn't getting called at all although I can see the connection is being made and an answer is coming back. 
In your manifest, try using your package's name for the BroadcastReceiver's intent category. So,

From this:
<category android:name="com.google.android.gcm.client"/>
To this:
<category android:name="com.commonsware.android.gcm.client"/>

With this change, your code works (tested under 2.3.3 emulator) and gets on to the next step and we can see the onRegister message now. 
Since this is pre-3, make sure the device has an account ofcourse, else we get a onError ACCOUNT_MISSING. 
--
J. Carlos Navea

Felipe Leme

unread,
Aug 14, 2012, 4:04:03 PM8/14/12
to andro...@googlegroups.com
The onRecoverableError() is called when the registration returned an error 503; the library will automatically try to reconnect, but you could override that method if you want take another action.

As others mentioned, my guess is also that the problem is the receiver's category - on 4.1 the category is not required anymore, hence the app worked. If you called GCMRegistrar.checkDevice() on onCreate() (instead of onClick()), it should have detected that misconfiguration.

Mark Murphy

unread,
Aug 14, 2012, 4:07:13 PM8/14/12
to andro...@googlegroups.com
On Tue, Aug 14, 2012 at 3:59 PM, J.Carlos Navea <loc...@gmail.com> wrote:
> It appears the BroadcastReceiver isn't getting called at all although I can
> see the connection is being made and an answer is coming back.
> In your manifest, try using your package's name for the BroadcastReceiver's
> intent category. So,
>
> From this:
> <category android:name="com.google.android.gcm.client"/>
> To this:
> <category android:name="com.commonsware.android.gcm.client"/>

I am an idiot. My apologies for screwing that up, again.

> With this change, your code works (tested under 2.3.3 emulator)

Yes, it is working now. Thanks!

Mark Murphy

unread,
Aug 14, 2012, 4:08:11 PM8/14/12
to andro...@googlegroups.com
On Tue, Aug 14, 2012 at 4:04 PM, Felipe Leme <feli...@android.com> wrote:
> As others mentioned, my guess is also that the problem is the receiver's
> category - on 4.1 the category is not required anymore, hence the app
> worked. If you called GCMRegistrar.checkDevice() on onCreate() (instead of
> onClick()), it should have detected that misconfiguration.

What is magic about onCreate() rather than onClick()?

Mark Murphy

unread,
Aug 14, 2012, 4:11:47 PM8/14/12
to andro...@googlegroups.com
On Tue, Aug 14, 2012 at 4:08 PM, Mark Murphy <mmu...@commonsware.com> wrote:
> On Tue, Aug 14, 2012 at 4:04 PM, Felipe Leme <feli...@android.com> wrote:
>> As others mentioned, my guess is also that the problem is the receiver's
>> category - on 4.1 the category is not required anymore, hence the app
>> worked. If you called GCMRegistrar.checkDevice() on onCreate() (instead of
>> onClick()), it should have detected that misconfiguration.
>
> What is magic about onCreate() rather than onClick()?

FWIW, I just tried checkDevice() from onCreate(), and even with a
messed-up category on the <receiver>, there are no errors reported,
either in LogCat or via an exception.

martianoo

unread,
Aug 14, 2012, 4:49:39 PM8/14/12
to andro...@googlegroups.com
Hi carlos,
i did thid


On Tuesday, August 14, 2012 8:59:41 PM UTC+1, J.Carlos Navea wrote:
Hi Mark,

It appears the BroadcastReceiver isn't getting called at all although I can see the connection is being made and an answer is coming back. 
In your manifest, try using your package's name for the BroadcastReceiver's intent category. So,

From this: <category android:name="com.commonsware.
android"/>
and it works on both avd 2.2 and 2.3.3 but not on real devices running 4.1

martianoo

unread,
Aug 14, 2012, 4:54:45 PM8/14/12
to andro...@googlegroups.com
Sorry this: this: <category android:name="com.test.push_test"/> and it works on both avd 2.2 and 2.3.3 but not on real devices running 4.1 .
Note: com.test.push_test being my package name. and i should change it to:
this: <category android:name="com.test.push_test.gcm.client"/>and it works on both avd 2.2 and 2.3.3 but not on real devices running 4.1 ?

Mark Murphy

unread,
Aug 14, 2012, 5:01:46 PM8/14/12
to andro...@googlegroups.com
On Tue, Aug 14, 2012 at 4:54 PM, martianoo <myphi...@gmail.com> wrote:
> Sorry this: this: <category android:name="com.test.push_test"/> and it works
> on both avd 2.2 and 2.3.3 but not on real devices running 4.1 .
> Note: com.test.push_test being my package name. and i should change it to:
> this: <category android:name="com.test.push_test.gcm.client"/>and it works
> on both avd 2.2 and 2.3.3 but not on real devices running 4.1 ?

No, the .gcm.client was part of my application's package name. Here is
the complete working sample discussed on this thread, updated:

https://github.com/commonsguy/cw-omnibus/tree/master/Push/GCMClient

martianoo

unread,
Aug 14, 2012, 5:04:55 PM8/14/12
to andro...@googlegroups.com
Yes sorry im ant idiot :)
Plz the android-support-v4.jar file is for what purpose?

Mark Murphy

unread,
Aug 14, 2012, 5:16:35 PM8/14/12
to andro...@googlegroups.com
On Tue, Aug 14, 2012 at 5:04 PM, martianoo <myphi...@gmail.com> wrote:
> Plz the android-support-v4.jar file is for what purpose?

Ah, that is not required -- it was put there automatically by Eclipse.
I have removed it from the sample project.

martianoo

unread,
Aug 14, 2012, 5:20:46 PM8/14/12
to andro...@googlegroups.com
It's because i tested my app that's using CCM on AVD 2.2 and 2.3.3 and i sent it to my client but he is running Sams Galaxy S2 but he says it's not working.i thought that jar file could help me.

Liza Jenifer

unread,
Apr 10, 2014, 6:16:13 AM4/10/14
to andro...@googlegroups.com
I have a use case where I need to update hundreds of tablets which are wi-fi only with my app and
I want to use GCM to accomplish this goal. However, what I could not figure out from the docs is
if I can register a wi-fi only device either w/ the IP (which might change based on the location)
or using the development device ID or the wi-fi mac address. Which of the three that I mentioned
are reliable ways of sending notifications to update w/ a newer version of my app? If none of these
are the right choices, what are my options since I can't have a phone number associated with
these devices.

Best 7 Inch Tablet
Reply all
Reply to author
Forward
0 new messages