Back to project page droidBBpush.
The source code is released under:
This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...
If you think the Android project droidBBpush listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.arg3.examples.droidbb.gcm; /* w w w .ja v a2 s . co m*/ import android.app.IntentService; import android.content.Intent; import android.os.Bundle; import com.arg3.examples.droidbb.MainApplication; import com.arg3.examples.droidbb.PushNotifier; import com.google.android.gms.gcm.GoogleCloudMessaging; import javax.inject.Inject; public class GCMIntentService extends IntentService { private static final String TAG = GCMIntentService.class.getName(); @Inject PushNotifier notifier; public GCMIntentService() { super(GCMIntentService.class.getSimpleName()); } @Override public void onCreate() { super.onCreate(); MainApplication app = (MainApplication) getApplication(); app.inject(this); } @Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { /* * Filter messages based on message type. Since it is likely that GCM * will be extended in the future with new message types, just ignore * any message types you're not interested in, or that you don't * recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { notifier.postError(extras); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { notifier.postDeleted(extras); } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { notifier.postMessage(extras); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GCMBroadcastReceiver.completeWakefulIntent(intent); } }