2013-03-07 214 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,這是與包檢查的名稱問題它仔細