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.