Overview

Skill Level: Intermediate

The Xamarin Sample application uses FCM by default, if you want to test the Sample application with GCM, follow the following steps.

Prerequisites

An existing Xamarin IBM Mobile App Messaging integration that uses Firebase Cloud Messaging (FCM).

Step-by-step

  1. Delete file google-services.json from project, if present.

  2. Edit MceConfig.json file.

    A. Change “messagingService” value to “gcm”
    B. Put GCM Sender Id in “senderId” value

  3. Edit AndroidManifest.xml file (click source view at bottom).

    A. Add these lines inside the <application> node.

    <service android:name="com.ibm.mce.sdk.gcm.MceGcmListenerService" android:exported="false" >
    <intent-filter>
    <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    </intent-filter>
    </service>
    
    <receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:priority="999">
    <intent-filter android:permission="com.google.android.c2dm.permission.SEND" >
    <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    <category android:name="$PACKAGE_NAME" />
    </intent-filter>
    <intent-filter android:permission="com.google.android.c2dm.permission.SEND" android:priority="999">
    <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
    <category android:name="$PACKAGE_NAME" />
    </intent-filter>
    </receiver>
    

    B. Remove these lines.

    <service
        android:name="com.ibm.mce.sdk.fcm.FcmInstanceIdService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>
    <service
        android:name="com.ibm.mce.sdk.fcm.FcmMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
    </service>
    <receiver
      android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
      android:exported="false" />
    
    <receiver
      android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
      android:exported="true"
      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="${applicationId}" />
        </intent-filter>
    </receiver>
    
  4. Remove Packages from Xamarin Android Project

    • Xamarin.Firebase.Messaging
    • Xamarin.Firebase.Iid
    • Xamarin.Firebase.Common
  5. Add Packages to Xamarin Android Project

    • Xamarin.GooglePlayServices.GCM

Join The Discussion

Your email address will not be published. Required fields are marked *