7
votes

I have an app in Google Play with 5000 downloads.

Of those 5000, 900 have failed to store a GCM Registration ID on my server.

I am concerned about having an 18% failure rate and am struggling to find out why this is happening. It is definitely not an issue passing an Id to my server and storing, so I assume it must be a failure of registration. Has anyone come across anything like this with their projects? Code as below:

// Fired every time the app is booted in Main Activity
private void setupGCM()
{
    String gcmRegId = GCMRegistrar.getRegistrationId(this);
    if (gcmRegId.equals(""))
    {
        GCMRegistrar.register(this, AppProperties.GCM_SENDER_ID);
    } else
    {
        // This is well tested and is not the issue
        ServerUtils.sUpdatePushToken(this, gcmRegId);
    }
}

// GCMIntentService Class onRegistered
@Override
protected void onRegistered(Context context, String registrationId)
{
    mContext = context;
    if (!registrationId.equals(""))
    {
        AppProperties.GCM_REGISTRATION_ID = registrationId;
        new UpdateGCMRegistrationIdAsync().execute();
    } else
    {
        GCMRegistrar.setRegisteredOnServer(context, false);
    }
}

// GCMIntentService Class  My Async class for updating Reg Id
private class UpdateGCMRegistrationIdAsync extends AsyncTask<Integer, Integer, Void>
{
    @Override
    protected Void doInBackground(Integer... params)
    {           
        ServerUtils.sUpdatePushToken(mContext, AppProperties.GCM_REGISTRATION_ID);
        return null;
    }
}
4
.equals("") is not recommended. try regId.trim().length() > 0 - drulabs
Appreciate your answer, however it is documented by google in the GCM demo with .equals(""). Plus would this work for 4100 devices and not for 900? - TommyGuns21
As a side note. I originally used regId.trim().length(). The same intermittent issue occurred then - TommyGuns21

4 Answers

4
votes

I just dealt with an issue that may turn out to be the same as yours. Devices with Android less than 4.1 failed to register with GCM. Here is my post from android-gcm google group:

Ok, got it solved. Thanks to J.Carlos Navea and Mark Murphy in this thread:
https://groups.google.com/forum/?fromgroups=#!searchin/android-gcm/onRegister/android-gcm/CqMRN4gVRpY/AGphcX1AuhgJ

The issue was the <category> tag in the receiver declaration. It is required for anything less than 4.1
Use your package name there. Additionally, check to make sure that the <permission> and <uses-permission>
tags use the same string/name. I was getting away with that one as well on 4.1
2
votes

There are some things that makes the GCM doesn't works, like:

A google accounts that is not syncronized.

In Android 3.2+ when the user "force stop" the application, gcm doesn't works too.

1
votes

Are you handling the situation where the GCM registration fails? If you're using GCMIntentService, make sure you're implementing the following:

@Override
protected void onError(Context context, String regid) {
   // Handle error condition.
}
0
votes

I had the same problem, some devices didnt registered, i checked my manisfest and it was a problem with the name of the package check it carefully