0
從官方website,我下載GCM的一個例子,有一個可以檢測刷新令牌服務,代碼如下:GCM:我應該在Android中自己啓動InstanceIDListenerService嗎?
public class MyInstanceIDListenerService extends InstanceIDListenerService {
private static final String TAG = "MyInstanceIDLS";
/**
* Called if InstanceID token is updated. This may occur if the security of
* the previous token had been compromised. This call is initiated by the
* InstanceID provider.
*/
// [START refresh_token]
@Override
public void onTokenRefresh() {
// Fetch updated Instance ID token and notify our app's server of any changes (if applicable).
Intent intent = new Intent(this, RegistrationIntentService.class);
startService(intent);
}
// [END refresh_token]
}
我的問題是:我應該寫代碼來啓動自己服務? 就像:
startService(new Intent(getActivity(), MyInstanceIDListenerService.class));
謝謝,你能給我更多的細節,Google Play服務,如何啓動它(哪個類啓動它)?就像「gcmListenerService」由「com.google.android.gms.gcm.GcmReceiver」啓動,你能告訴我InstanceIDListenerService是如何啓動的嗎? – fhlkm
Google Play服務始終在運行。 InstanceIDListenerService也將由GcmReceiver啓動。 –
如果sendRegistrationIdTo服務器調用失敗,該怎麼辦? – Javanator