我在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