Skip to content

Instantly share code, notes, and snippets.

@cirocosta
Created November 5, 2013 17:21
Show Gist options
  • Save cirocosta/7322664 to your computer and use it in GitHub Desktop.
Save cirocosta/7322664 to your computer and use it in GitHub Desktop.
BroadcastReceiver e Service
public class MeuGcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GcmIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
public class MeuGcmService extends IntentService {
public static final int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
public GcmIntentService() {
super("GcmIntentService");
}
@Override
onHandleIntent(Intent intent){
Bundle extras = intent.getExtras();
//processamento como desejar
processaMensagem(extras);
MeuGcmService.completeWakefulIntent(intent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment