If you are planning to start a fresh integration, please visit this documentation. This doc is exclusively for the developers who are planning to migrate from the SDK with GCM to the SDK with FCM.
1. Import your GCM project as a Firebase project
2. Add Firebase to your project
3. Add FCM sdk in the app-level build.gradle
dependencies {
compile "com.google.firebase:firebase-messaging:9.0.0"
}
4. Remove the permissions required by GCM
- AndroidManifest.xml - Before
<!-- For GCM notification -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- Important: Replace 'com.blueshift.sampleapp' with your app's package name -->
<permission
android:name="com.blueshift.sampleapp.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<!-- Important: Replace 'com.blueshift.sampleapp' with your app's package name -->
<uses-permission android:name="com.blueshift.sampleapp.permission.C2D_MESSAGE" />
<!-- For scheduling network operations effectively -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- For analytical purpose (optional) -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
- AndroidManifest.xml - After
<uses-permission android:name="android.permission.INTERNET" />
<!-- For scheduling network operations effectively -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- For analytical purpose (optional) -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
- AndroidManifest.xml - Before
<receiver
android:name="com.blueshift.gcm.GCMBroadcastReceiver"
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" />
<!-- Important: Replace 'com.blueshift.sampleapp' with your app's package name -->
<category android:name="com.blueshift.sampleapp" />
</intent-filter>
</receiver>
<service android:name="com.blueshift.gcm.GCMIntentService" />
<!-- Important: Replace 'com.blueshift.sampleapp' with your app's package name -->
<receiver android:name="com.blueshift.rich_push.RichPushBroadcastReceiver">
<intent-filter>
<action android:name="com.blueshift.sampleapp.RICH_PUSH_RECEIVED" />
<category android:name="com.blueshift.sampleapp" />
</intent-filter>
</receiver>
<meta-data
android:name="com.blueshift.gcm_sender_id"
android:value="id:YOUR_GCM_SENDER_ID" />
- AndroidManifest.xml - After
<!-- No receiver needed. Yay! -->
- AndroidManifest.xml - Before
<receiver android:name="com.blueshift.rich_push.RichPushActionReceiver">
<!-- Important: Replace 'com.blueshift.sampleapp' with your app's package name -->
<intent-filter>
<action android:name="com.blueshift.sampleapp.ACTION_VIEW" />
<action android:name="com.blueshift.sampleapp.ACTION_BUY" />
<action android:name="com.blueshift.sampleapp.ACTION_OPEN_CART" />
<action android:name="com.blueshift.sampleapp.ACTION_OPEN_OFFER_PAGE" />
<action android:name="com.blueshift.sampleapp.ACTION_OPEN_APP" />
<category android:name="com.blueshift.sampleapp" />
</intent-filter>
</receiver>
- AndroidManifest.xml - After
<!-- Important Note: This change is not required if you're using SDK version 2.0.0 and above -->
<receiver android:name="com.blueshift.rich_push.RichPushActionReceiver">
<!-- Important: Replace 'com.blueshift.sampleapp' with your app's package name -->
<intent-filter>
<action android:name="com.blueshift.sampleapp.ACTION_VIEW" />
<action android:name="com.blueshift.sampleapp.ACTION_BUY" />
<action android:name="com.blueshift.sampleapp.ACTION_OPEN_CART" />
<action android:name="com.blueshift.sampleapp.ACTION_OPEN_OFFER_PAGE" />
<action android:name="com.blueshift.sampleapp.ACTION_OPEN_APP" />
<category android:name="com.blueshift.sampleapp" />
</intent-filter>
</receiver>
Register the FCM services for Blueshift SDK
For SDK version v1.1.2.fcm
and above, register the following services to do the FCM registration and Message handling by the SDK.
- XML
<service android:name="com.blueshift.fcm.BlueshiftMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="com.blueshift.fcm.BlueshiftInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>