FCM Support
GCM has been officially removed from the SDK. The following information is useful for existing and new Mixpanel customers:
How to remove GCM from an existing app
- Open your
AndroidManifest.xml
file an remove the following permissions since they are included in FCM already:
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="YOUR_PACKAGE.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="YOUR_PACKAGE.permission.C2D_MESSAGE" />
- Remove the following tag from your
AndroidManifest.xml
file:
<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_PACKAGE" />
</intent-filter>
</receiver>
- Remove GCM from your gradle dependencies:
dependencies {
compile 'com.google.android.gms:play-services-gcm:10.0.1' // Remove this line
....
}
- Remove any reference to
People.initPushHandling(senderId)
since it's no longer used:
MixpanelAPI.getInstance(this).getPeople().initPushHandling(SENDER_ID); // Remove this line
How to add FCM to your app
- Add the following tag inside your
application
tag in yourAndroidManifest.xml
file:
<application>
...
<service
android:name="com.mixpanel.android.mpmetrics.MixpanelFCMMessagingService"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
...
</application>
- Add FCM to your gradle dependencies. You should already have Google Services added, but double check that's the case:
buildscript {
...
dependencies {
classpath 'com.google.gms:google-services:4.1.0'
...
}
}
dependencies {
implementation 'com.google.firebase:firebase-messaging:17.3.4' // Must be higher than 16.2.0
...
}
apply plugin: 'com.google.gms.google-services'
-
Place your
google-services.json
file to your Android project. You can grab that file from your Firebase Console center. -
We suggest to update your GCM API Key on mixpanel.com and use your FCM Server Key instead. Notice that your existing GCM Key it's now called Legacy token and it is still supported.
-
Enjoy!