Android GCM有些设备没有注册

Tom*_*s21 7 android google-cloud-messaging

我有一个Google Play应用,下载量为5000.

在这5000个中,900个未能在我的服务器上存储GCM注册ID.

我担心失败率为18%,并且正在努力找出这种情况发生的原因.这绝对不是将Id传递给我的服务器并存储的问题,所以我认为它必须是注册失败.有没有人在他们的项目中遇到过这样的事情?代码如下:

// 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;
    }
}
Run Code Online (Sandbox Code Playgroud)

Gui*_*res 2

有一些因素会导致 GCM 无法工作,例如:

未同步的 Google 帐户。

在 Android 3.2+ 中,当用户“强制停止”应用程序时,gcm 也不起作用。