public class GCMReceiver
extends android.content.BroadcastReceiver
You can use GCMReceiver to report Google Cloud Messaging registration identifiers
to Mixpanel, and to display incoming notifications from Mixpanel to
the device status bar. Together with MixpanelAPI.People.initPushHandling(String)
this is the simplest way to get up and running with notifications from Mixpanel.
To enable GCMReceiver in your application, add a clause like the following to the <application> tag of your AndroidManifest.xml. (Be sure to replace "YOUR APPLICATION PACKAGE NAME" in the snippet with the actual package name of your app.)
<receiver android:name="com.mixpanel.android.mpmetrics.GCMReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="YOUR APPLICATION PACKAGE NAME" />
</intent-filter>
</receiver>
In addition, GCMReceiver will also need the following permissions configured in your AndroidManifest.xml file:
<!-- Be sure to change YOUR_PACKAGE_NAME to the real name of your application package -->
<permission android:name="YOUR_PACKAGE_NAME.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="YOUR_PACKAGE_NAME.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
Once the GCMReceiver is configured, the only thing you have to do to
get set up Mixpanel messages is call MixpanelAPI.People.identify(String)
with a distinct id for your user, and call MixpanelAPI.People.initPushHandling(String)
with the your Google API project identifier.
MixpanelAPI.People people = mMixpanelAPI.getPeople();
people.identify("A USER DISTINCT ID");
people.initPushHandling("123456789123");
If you would prefer to handle either sending a registration id to Mixpanel yourself
but allow GCMReceiver to handle displaying Mixpanel messages, remove the
REGISTRATION intent from the GCMReceiver <receiver>
tag, and call
MixpanelAPI.People.setPushRegistrationId(String)
in your own REGISTRATION handler.
Modifier and Type | Class and Description |
---|---|
protected static class |
GCMReceiver.NotificationData |
Constructor and Description |
---|
GCMReceiver() |
Modifier and Type | Method and Description |
---|---|
protected android.app.Notification |
makeNotificationSDK11OrHigher(android.content.Context context,
android.app.PendingIntent intent,
GCMReceiver.NotificationData notificationData) |
protected android.app.Notification |
makeNotificationSDK16OrHigher(android.content.Context context,
android.app.PendingIntent intent,
GCMReceiver.NotificationData notificationData) |
protected android.app.Notification |
makeNotificationSDK21OrHigher(android.content.Context context,
android.app.PendingIntent intent,
GCMReceiver.NotificationData notificationData) |
protected android.app.Notification |
makeNotificationSDK26OrHigher(android.content.Context context,
android.app.PendingIntent intent,
GCMReceiver.NotificationData notificationData) |
protected android.app.Notification |
makeNotificationSDKLessThan11(android.content.Context context,
android.app.PendingIntent intent,
GCMReceiver.NotificationData notificationData) |
void |
onReceive(android.content.Context context,
android.content.Intent intent) |
abortBroadcast, clearAbortBroadcast, getAbortBroadcast, getDebugUnregister, getResultCode, getResultData, getResultExtras, goAsync, isInitialStickyBroadcast, isOrderedBroadcast, peekService, setDebugUnregister, setOrderedHint, setResult, setResultCode, setResultData, setResultExtras
public void onReceive(android.content.Context context, android.content.Intent intent)
onReceive
in class android.content.BroadcastReceiver
protected android.app.Notification makeNotificationSDKLessThan11(android.content.Context context, android.app.PendingIntent intent, GCMReceiver.NotificationData notificationData)
protected android.app.Notification makeNotificationSDK11OrHigher(android.content.Context context, android.app.PendingIntent intent, GCMReceiver.NotificationData notificationData)
protected android.app.Notification makeNotificationSDK16OrHigher(android.content.Context context, android.app.PendingIntent intent, GCMReceiver.NotificationData notificationData)
protected android.app.Notification makeNotificationSDK21OrHigher(android.content.Context context, android.app.PendingIntent intent, GCMReceiver.NotificationData notificationData)
protected android.app.Notification makeNotificationSDK26OrHigher(android.content.Context context, android.app.PendingIntent intent, GCMReceiver.NotificationData notificationData)