Migrating from GCM to FCM
Google’s GCM services are deprecating as of April 1st, 2019, after which the support and further features improvements are not possible. As a replacement for GCM, google’s Firebase Cloud Messaging should be integrated with.
If you have already integrated with Gamooga’s GCM SDK, kindly follow the instructions below to migrate smoothly to FCM. And if you are already using FCM, you can skip this.
1. Adding Project as FCM project
-
In the Firebase console, select Add Project.
-
Select your GCM project from the list of existing Google Cloud projects, and select Add Firebase.
-
In the Firebase welcome screen, select Add Firebase to your Android App.
-
Provide your package name and SHA-1, and select Add App. A new google-services.json file for your Firebase app is downloaded.
2. Replacing GCM with FCM Dependencies
- Remove this line from your app/build.gradle :
compile project(':gamooga-targetact-client-release')
- Check if this is already added if not add them
compile "com.google.android.gms:play-services:+"
- Now add the Maven URL for Gamooga android-sdk. Add the following to the project build.gradle file:
allprojects { repositories { jcenter() maven { // add this line for gamooga repo, the above lines may already be there url 'http://maven.gamooga.com:8081/artifactory/libs-release' } } }
- Add the following in the main application build.gradle file for FCM:
compile "com.gamooga.targetact:gamooga-targetact-client:1.8.8.10"
3. Permissions
-
Check If these permission are already added if not add them
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Note: Gamooga does not need this permission anymore
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
4. Removing old Configurations
Replace the old Gamooga Configuration from AndroidManifest.xml with the new configuration.
Old GCM Configuration to be removed:
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" />
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="Your_app_id" />
</intent-filter>
</receiver>
<service
android:name="com.gamooga.targetact.client.GamoogaGcmListenerService"
android:exported="false" />
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name="com.gamooga.targetact.client.GamoogaInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<service
android:name="com.gamooga.targetact.client.RegistrationIntentService"
android:exported="false">
</service>
Replace it with the New FCM configuration as below:
<service android:name="com.gamooga.targetact.client.fcmpush.GamoogaInstanceIDListenerService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name="com.gamooga.targetact.client.fcmpush.GamoogaFCMListener">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Additional Information
i. Deprecated Methods
The following had been deprecated from our SDK.
tac.getPushRegistrationId();
tac.saveSessionTimeout(int timeout);
ii. Changes
ICallback
is now calledGamoogaCallback
- To get events the
callback
method is nowonGetEvents
- For custom action the
callback
method is nowonCustomActionReceived
iii. Additions
-
If Client is using Gamooga FCM services
GamoogaCallback call now have one more callback method to retrieve the push Messages as follows
onPushMessageReceived(RemoteMessage message)
-
If Client is using their own FCM services, Gamooga will bundle the push body into pending intent
Whenever a user clicks on push notification, Client can retrieve the push body as below.
getIntent().getBundleExtra("__push_body");
-
For Oreo, we can create the Notification Channels & set priority.
<meta-data android:name="GAMOOGA_PUSH_CHANNEL_NAME" android:value="Gamooga Custom" /> <meta-data android:name="GAMOOGA_PUSH_CHANNEL_ID" android:value="gamooga_custom_id" /> <meta-data android:name="GAMOOGA_PUSH_CHANNEL_DESCRIPTION" android:value="Gamooga Custom description" /> <meta-data android:name="GAMOOGA_PUSH_CHANNEL_IMPORTANCE" android:value="3" /> <meta-data android:name="PUSH_KEY_PROPERTY" android:value="my_app_push" />