Firebase push notifications with xamarin forms

mhmdmhmd Member ✭✭

I've added a project and an application on firebase which is linked to my testing application I created with Xamarin Forms. I downloaded the json file and placed it in my application and set the build action to "GoogleServicesJson". Also, I installed the "Plugin.FirebasePushNotification" package to my project. This is my code in my Xamarin Forms project:

AndroidMainfest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.TestingNotification">
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="27" />
  <uses-permission android:name="android.permission.INTERNET" />
    <application android:label="TestingNotification.Android">
      <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>
    </application>
</manifest>

MainActivity:

protected override void OnCreate(Bundle savedInstanceState)

    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;

    base.OnCreate(savedInstanceState);
    global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
    LoadApplication(new App());

    FirebasePushNotificationManager.ProcessIntent(this, Intent);
    FirebasePushNotificationManager.Initialize(this, true);

    // FirebasePushNotificationManager.Initialize(this,false);
    if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
    {
        //Change for your default notification channel id here
        FirebasePushNotificationManager.DefaultNotificationChannelId = "quayo-project";

        //Change for your default notification channel name here
        FirebasePushNotificationManager.DefaultNotificationChannelName = "Quayo-Project";
    }
    //If debug you should reset the token each time.
    //Handle notification when app is closed here
    CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
    {
        Toast.MakeText(this, "ok", ToastLength.Long);
    };

}

And the json file:

{
  "project_info": {
    "project_number": "358226749019",
    "firebase_url": "https://quayo-project.firebaseio.com",
    "project_id": "quayo-project",
    "storage_bucket": "quayo-project.appspot.com"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1:358226749019:android:54b60a3809576332",
        "android_client_info": {
          "package_name": "com.companyname.TestingNotification"
        }
      },
      "oauth_client": [
        {
          "client_id": "358226749019-bgbp51sguavj4m10ahooqv537h5fgppd.apps.googleusercontent.com",
          "client_type": 3
        }
      ],
      "api_key": [
        {
          "current_key": "AIzaSyBsR2Ixk_psObHy-Zjde8GzYbSv_Z_6Bxg"
        }
      ],
      "services": {
        "appinvite_service": {
          "other_platform_oauth_client": [
            {
              "client_id": "358226749019-bgbp51sguavj4m10ahooqv537h5fgppd.apps.googleusercontent.com",
              "client_type": 3
            }
          ]
        }
      }
    }
  ],
  "configuration_version": "1"
}

But I still can't receive any notifications when I try A/B test or cloud messaging with firebase and when I run the app no user is added to the firebase app. So what am I missing here? can someone help? Thanks in advance

Sign In or Register to comment.