Last active
January 18, 2016 14:09
-
-
Save renaudmathieu/56a3f0a8a2f898fd81ae to your computer and use it in GitHub Desktop.
Using your own BroadcastReceiver with Localytics and any other Receiver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GCMBroadcastReceiver extends BroadcastReceiver { | |
private static final String TAG = GCMBroadcastReceiver.class.getSimpleName(); | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
if ("com.google.android.c2dm.intent.REGISTRATION".equals(intent.getAction())) { | |
// Register Localytics (this will call Localytics.handleRegistration(intent)) | |
new PushReceiver().onReceive(context, intent); | |
} else if ("com.google.android.c2dm.intent.RECEIVE".equals(intent.getAction())) { | |
if (intent.getExtras().containsKey("ll")) { | |
// Send the notification to Localytics | |
new PushReceiver().onReceive(context, intent); | |
/* | |
Ordered broadcasts (sent with Context.sendOrderedBroadcast) are delivered to one receiver at a time. | |
As each receiver executes in turn, it can propagate a result to the next receiver, | |
or it can completely abort the broadcast so that it won't be passed to other receivers. | |
The order receivers run in can be controlled with the android:priority attribute | |
of the matching intent-filter; receivers with the same priority will be run in an arbitrary order. | |
*/ | |
// Let's consume the intent for other Receiver | |
if (isOrderedBroadcast()) { | |
setResultCode(Activity.RESULT_CANCELED); | |
abortBroadcast(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment