2012-07-12 117 views
1

我正在嘗試將推送通知功能添加到我的應用程序,但我有奇怪的問題。註冊 - 從Android GCM取消註冊設備

在我第一次嘗試,我得到了設備的REGID;但在該設備試圖從GCM自行註銷之後;事實上,它成功了,因爲我失去了REGID,但不是我再也得不到它了。

在LogCat中,我看到了這些行。

07-12 08:40:25.615: V/GCMRegistrar(10648): Registering receiver 
07-12 08:40:25.620: D/GCMRegistrar(10648): resetting backoff for PACKAGENAME 
07-12 08:40:25.635: V/GCMRegistrar(10648): Unregistering app PACKAGENAME 
07-12 08:40:28.570: D/GCMRegistrar(10648): resetting backoff for PACKAGENAME 
07-12 08:40:28.570: V/GCMRegistrar(10648): Unregistering app PACKAGENAME 
07-12 08:40:29.125: D/GCMRegistrar(10648): resetting backoff for PACKAGENAME 
07-12 08:40:29.130: V/GCMRegistrar(10648): Unregistering app PACKAGENAME 
07-12 08:40:39.655: D/GCMRegistrar(10648): resetting backoff for PACKAGENAME 
07-12 08:40:39.660: V/GCMRegistrar(10648): Unregistering app PACKAGENAME 
07-12 08:40:40.605: D/GCMRegistrar(10648): resetting backoff for PACKAGENAME 
07-12 08:40:40.605: V/GCMRegistrar(10648): Unregistering app PACKAGENAME 
07-12 08:40:41.350: D/GCMRegistrar(10648): resetting backoff for PACKAGENAME 
07-12 08:40:41.350: V/GCMRegistrar(10648): Unregistering app PACKAGENAME 
07-12 08:40:43.255: D/GCMRegistrar(10648): resetting backoff for PACKAGENAME 
07-12 08:40:43.255: V/GCMRegistrar(10648): Unregistering app PACKAGENAME 

我試着將GCM Demo Application的代碼實現到我的應用程序中,所以這裏是代碼。

GCMRegistrar.checkDevice(this); 
GCMRegistrar.checkManifest(this); 

registerReceiver(mHandleMessageReceiver, new IntentFilter(DISPLAY_MESSAGE_ACTION)); 
final String regId = GCMRegistrar.getRegistrationId(this); 

if (regId.equals("")) { 
    // Automatically registers application on 
    // startup. 
    GCMRegistrar.register(this, SENDER_ID); 
} else { 
    Log.v(TAG, "Already registered"); 
    // Device is already registered on GCM, needs to 
    // check if it is 
    // registered on our server as well. 
    if (!GCMRegistrar.isRegisteredOnServer(this)) { 
     // Try to register again, but not in the UI 
     // thread. 
     // It's also necessary to cancel the thread 
     // onDestroy(), 
     // hence the use of AsyncTask instead of a 
     // raw thread. 
     final Context context = this; 
     mRegisterTask = new AsyncTask<Void, Void, Void>() { 
      mRegisterTask.execute(null, null, null); 
     } 
    } 
} 

回答

2

,我發現我的問題,它都是我的錯,並sillyness的。

我已將GCMRegistrar.unregister()代碼添加到評估中;所以調試的每一步都會導致重新評估此代碼並調用取消註冊。

我不想把它刪除,可能是有一個人跟我一樣;)

+0

如何檢查設備是否在GCM./ – 2013-04-13 08:07:52

+0

最後絃樂的RegID = GCMRegistrar.getRegistrationId(本)註冊與否;這條線給你答案。如果是空設備未註冊,則另行註冊。 – 2013-04-13 19:20:03