1

I'm developing an application on Xamarin.Forms. I'm using the following plug-in to get push notifications from Firebase. I'm working on a MacBook.

FirebasePushNotificationPlugin

https://github.com/CrossGeeks/FirebasePushNotificationPlugin

I tried;

This has not a solution. It's same with me.

https://github.com/CrossGeeks/FirebasePushNotificationPlugin/issues/153

There is no problem with iOS, but I get the error on Android.

Error: com.google.firebase.messaging package com.google.firebase.messaging.FirebaseMessagingService

and second error;

/Users/Username/Projects/MyProject/MyProject.Android/obj/Debug/android/src/md5f94c48bc84b2956c5a5be24cbc1fa7f2/PNFirebaseMessagingService.java(7,7): Error: error: cannot find symbol if (getClass () == PNFirebaseMessagingService.class) symbol: method getClass() location: class PNFirebaseMessagingService (MyProject.Android)

My Nuget packages are up to date. I couldn't figure out this error on the Android side, thank you.

user3186216
  • 39
  • 1
  • 7
  • Well, I have a feeling I will have to step in, can you please explain what steps have you taken so far! – FreakyAli Jan 31 '19 at 08:10
  • Here is a sample for Xamairn.Android.(https://developer.xamarin.com/samples/monodroid/Firebase/FCMNotifications/)You can refer to check problem where is. – Junior Jiang Feb 01 '19 at 08:32

1 Answers1

0

First: the library you post is really outdated (2+ years). You should use Xamarin.Firebase.Messaging.

Second: don't forget to add the google-services.json file on Android folder and GoogleService-Info.plist on iOS folder and set the Build Action as GoogleServiceJson.

Third: You must have a way to detect if the phone has Google Play Services enabled.

So you must add this on the AndroidManifest:

<application android:label="YourAppName">
<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>

Then create a service:

namespace YourAppName.Droid
{
    [Service]
    [IntentFilter(new [] { "com.google.firebase.INSTANCE_ID_EVENT" })]
    public class FirebaseService : FirebaseInstanceIdService
    {
        const string TAG = "MyFirebaseIIDService";

        public override void OnTokenRefresh()
        {
            var refreshedToken = FirebaseInstanceId.Instance.Token;
            Log.Debug(TAG, "Refreshed token: " + refreshedToken);
            SendRegistrationToServer(refreshedToken);
        }

        void SendRegistrationToServer(string token)
        {
            // Add custom implementation, as needed.
        }
    }
}

And last, add this method on your MainActivity and call it on the OnCreate method:

public bool CheckForGoogleServices()
        {
            int resultCode = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(this);
            if (resultCode != ConnectionResult.Success)
            {
                if (GoogleApiAvailability.Instance.IsUserResolvableError(resultCode))
                {
                    Toast.MakeText(this, GoogleApiAvailability.Instance.GetErrorString(resultCode), ToastLength.Long);
                }
                else
                {
                    Toast.MakeText(this, "This device does not support Google Play Services", ToastLength.Long);
                }
                return false;
            }
            return true;
}

In some android devices Google Play Services are not installed, so we need to ensure the user knows if can receieve push notifications.

And remember if you're using android emulator, install it Google Play Service on it.

FabriBertani
  • 1,606
  • 13
  • 24
  • Everything you said was already done. No problem in ios on same library, just getting this error on Android side. – user3186216 Jan 31 '19 at 06:19