Java tutorial
/* * Copyright (c) 2015 Matthieu Harl * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package fr.shywim.antoinedaniel.gcm; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.support.v4.content.WakefulBroadcastReceiver; public class GcmBroadcastReceiver 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. String msg = intent.getStringExtra("msg"); if (msg != null && msg.contains("update:")) { startWakefulService(context, intent.setComponent(comp)); setResultCode(Activity.RESULT_OK); } else { context.startService(intent.setComponent(comp)); setResultCode(Activity.RESULT_OK); } } }