1

This is the Messaging service class

[Service]
    [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
    class MyFirebaseMessagingService : FirebaseMessagingService
    {
        public override void OnMessageReceived(RemoteMessage message)
        {
            base.OnMessageReceived(message);
            SendNotification(message.GetNotification().Body);


    }

    private void SendNotification(string body)
    {
        var intent = new Intent(this, typeof(MainActivity));
        intent.AddFlags(ActivityFlags.ClearTop);
        var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

        var defaultSoundUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
        var notificationBuilder = new NotificationCompat.Builder(this)
            .SetSmallIcon(Resource.Drawable.Notification)
            .SetContentTitle("")
            .SetContentText(body)
            .SetAutoCancel(true)
            .SetSound(defaultSoundUri)
            .SetContentIntent(pendingIntent);

        var notificationManager = NotificationManager.FromContext(this);
        notificationManager.Notify(0, notificationBuilder.Build());
    }

this is the firebase id class

 [Service]
    [IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
    class MyFirebaseIdService : FirebaseInstanceIdService
    {

    public override void OnTokenRefresh()
    {
    base.OnTokenRefresh();
    Android.Util.Log.Debug("Refreshed Token:", 
    FirebaseInstanceId.Instance.Token);
    }

This is the main activity

Task.Run(() => {
var instanceId = FirebaseInstanceId.Instance;
instanceId.DeleteInstanceId();
Android.Util.Log.Debug("TAG", "{0} {1}", instanceId.Token, 
instanceId.GetToken(GetString(Resource.String.gcm_defaultSenderId), 
Firebase.Messaging.FirebaseMessaging.InstanceIdScope));


});
KENdi
  • 7,576
  • 2
  • 16
  • 31
  • When you app is closed, you can't manually handle notification, but you can still receive generic one. The one you set with your firebase parameters. – Nicolas Jul 06 '17 at 14:09
  • Since the client app is in Android, my answer [here](https://stackoverflow.com/a/39505298/4625829) might contain some helpful info. – AL. Jul 06 '17 at 17:06

0 Answers0