您需要設置鬧鐘退避一段時間後 重試登記您需要重試的意圖過濾器添加到在manifest.html接收申報和報警代碼可能是這個樣子
if ("SERVICE_NOT_AVAILABLE".equals(error)) {
long backoffTimeMs = C2DMessaging.getBackoff(context);
Log.d(TAG, "Scheduling registration retry, backoff = " + backoffTimeMs);
Intent retryIntent = new Intent(C2DM_RETRY);
PendingIntent retryPIntent = PendingIntent.getBroadcast(context,
0 /*requestCode*/, retryIntent, 0 /*flags*/);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + backoffTimeMs,
retryPIntent);
// Next retry should wait longer.
backoffTimeMs *= 2;
C2DMessaging.setBackoff(context, backoffTimeMs);
}
C2DMessaging是jumpnote應用一類可以在這裏找到http://code.google.com/p/jumpnote/source/checkout
UPDATE
確保日根據我對您的評論的回覆中的建議,您的清單文件中設置了重試權限。我的清單看起來是這樣的
<receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<!-- Receive the actual message -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="my.package.name" />
</intent-filter>
<!-- Receive the registration id -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="my.package.name" />
</intent-filter>
</receiver>
<receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RETRY"/>
<category android:name="io.modem" />
</intent-filter>
</receiver>
而且 - 這很容易測試在模擬器上 - 只需斷開P.C.從互聯網,你會得到重試事件服務不可用例外,直到你重新連接到互聯網
我已經看到,與RETRY意圖應用程序實際上從來沒有收到registrationId。在這種情況下,我們是否真的需要再次調用註冊意圖。 – sunil