2013-03-07 210 views
7

我在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; 
    } 
} 
+0

.equals(“”)不建议。请尝试regId.trim()。length()> 0 – drulabs 2013-03-07 16:13:40

+2

或'.isEmpty()' – 323go 2013-03-07 16:21:20

+1

欣赏您的答案,但它在谷歌的GCM演示中用.equals(“”)记录。另外,这将工作的4100设备,而不是900? – TommyGuns21 2013-03-07 16:36:47

回答

2

有一些事情,使GCM没有作品,如:

未syncronized一个谷歌账户。

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

+1

感谢您的回答,Google帐户会根据需要从Google Play下载应用程序进行同步。就停止使用而言,如果这对18%的用户来说是个问题,我会感到很惊讶。 – TommyGuns21 2013-03-07 16:45:36

+0

这是我遇到的一些问题,用户可能会改变syncronized acc并且现在不确定,但它会使“注册ID”发生变化,您必须在Web服务器中更改它。你应该考虑900也许他们不是新用户。 – 2013-03-07 17:15:25

4

我刚刚处理了一个可能与您的问题相同的问题。 Android小于4.1的设备无法注册GCM。这里是我的帖子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 
1

您是否正在处理GCM注册失败的情况?如果您使用GCMIntentService,确保你实现以下:

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

我有同样的问题,有些设备didnt注册,我检查了我manisfest,这是与包检查的名称问题它仔细