2012-07-04 36 views
0

this example,廣播接收機啓動意向服務。 在IntentService實例中,它啓動一個名爲runIntentInService的方法,該方法放入PowerManager.WakeLock對象中,而不是啓動該服務。GCM無法啓動手動註冊

現在,當我手動啓動註冊過程(從mainActivity)其中:

Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER"); 
    // sets the app name in the intent 
    registrationIntent.putExtra("app", PendingIntent.getBroadcast(mainActivity.this, 0, new Intent(), 0)); 
    registrationIntent.putExtra("sender", _senderID); 
    startService(registrationIntent); 
在IntentService

,PowerManager.WakeLock的對象還沒有初始化尚未,所以空。我使用this code來註冊mainActivity。 應該用the following代替嗎?

GCMRegistrar.checkDevice(this); 
GCMRegistrar.checkManifest(this); 
final String regId = GCMRegistrar.getRegistrationId(this); 
if (regId.equals("")) { 
    GCMRegistrar.register(this, SENDER_ID); 
} else { 
    Log.v(TAG, "Already registered"); 
} 

謝謝!

回答

0

GCMRegistrar只是一個輔助類,它和你所提到的完全相同,即發送寄存器意圖等。 所以不需要改變代碼。

+0

finaly我使用演示android gcm客戶端,它的工作原理。現在只需要處理服務器 – Li3ro