我在Google Play上有一个应用程序,下载量为5000次。Android GCM某些设备未注册
在这些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;
}
}
.equals(“”)不建议。请尝试regId.trim()。length()> 0 – drulabs 2013-03-07 16:13:40
或'.isEmpty()' – 323go 2013-03-07 16:21:20
欣赏您的答案,但它在谷歌的GCM演示中用.equals(“”)记录。另外,这将工作的4100设备,而不是900? – TommyGuns21 2013-03-07 16:36:47