Push notifications on Xamarin

@Nikita_Fedorishchev
I will test again, but the previous times the table remained empty.

Steps:

  • start app
  • I see the device in the table
  • in foreground send notification
  • the app receive the notificaction
  • go to background
  • send notification
  • the device shows the notification and click to open the app
  • close the app
  • send notification
  • the device shows the notification and click to open the app ( i think that uses a new token and register the device again)
  • send another notification
  • the app don’t show nothing and the table is empty

thanks for your support

Maria

@Maria_Regil, I will check this scenario. Please tell me your result, too.

@Nikita_Fedorishchev , the same result, the table is empty, it seems that remove the device when i send the notification

@Maria_Regil, we are working on the problem, I will let you know when the results are.
One more question. When you specify expiration time, records are not deleted?

Best regards, Nikita.

I haven’t tried it yet, I’ll try it and let you know.

Hello, @Maria_Regil .

We were unable to reproduce your problem. Could you provide a minimal reproducible example?

Regards, Nikita.

Hi @Nikita_Fedorishchev
I tried registering the device with expiration date and the same thing happened. So I have changed the initialization of firebase so that in debug it does not generate the token again and it seems that this way it works.

One thing that has caught my attention is that the Device ID is different, it changes when changing the token, should it be so?
And moving on to another topic, in the notifications in the title I see the name of the application, not the one I put in the “Title” field during the creation of the notification.

Thank you very much for your support
Maria

Hi, @Maria_Regil, the bug with DeviceId will be fixed in the next SDK update.
Thank you for your feedback.

As for the “Title”, you may have configured the Push Notifications incorrectly in the client application.
As far as I understand, you are using the following logic to receive Push notifications:

Pay attention to the section Android Initialization.

Best regards, Nikita.

Hi @Nikita_Fedorishchev ,
I have been checking the Firebase configuration and it is correct.
I am using the default PushNotificationhandle in the PushnotificationManager initialization and I have tried sending a push notification from Firebase and it arrives correctly with the title in place.

image
the first notification is from backendless (10 min) and the second is from Firebase (1min).

Thank you
Maria

@Maria_Regil, you can also independently process the data that comes with push notification. Here’s an example of how to do this:

  var values = JsonConvert.DeserializeObject<Dictionary<String, String>>( (String) notif.Data[ "android_immediate_push" ] );
  NotificationCompat.Builder builder = new NotificationCompat.Builder( this, "default" )
                                                             .SetContentTitle( values["contentTitle"] )
                                                             .SetContentText( (String) notif.Data["message"] )
                                                             .SetSmallIcon( Resource.Drawable.ic_mtrl_checked_circle );

  Notification notification = builder.Build();
  NotificationManager manager = GetSystemService( Context.NotificationService ) as NotificationManager;
  const int notificationId = 0;
  manager.Notify( notificationId, notification );


This is a test case (data processing variant), modify the code for your purposes.

Regards, Nikita.

Hi @Nikita_Fedorishchev,
I see what you say, but this way the plugin does not recognize the new notification, and also in the case of having the app in the background it duplicates the notification.
Looking at the plugin info:
“If NotificationContentTitleKey not set will look for title key value in the notification payload to set the title. If no title key present will use the application name as the notification title.”

but unfortunately in the payload of the backendkess notification there is no “title” field and the “contentTitle” field is inside “android_immediate_push”, so the plugin doesn’t find it.

thanks
Maria

@Maria_Regil, alternatively, you can not use PushNotificationManager.Initialize(), then notifications will not be duplicated. and write a method that will process the data.
I checked this just now.

Hi @Nikita_Fedorishchev ,
I’ve been with another project, sorry for the delay.
You say not to use the initialization for the plugin, but then how do I collect the token?
To register in Backendless I need the token, isn’t it?

image

although in the documentation there is a different function to register the device:

I don’t know if I am doing it correctly

Maria

Hello, @Maria_Regil .

I get the token using this method (no initialization in App.Android):

   CrossPushNotification.Current.OnTokenRefresh + = (s, p) =>
   {
     System.Diagnostics.Debug.WriteLine ($ "TOKEN REC: {p.Token}");
     Backendless.Messaging.RegisterDevice (CrossPushNotification.Current.Token);
   };

Unfortunately, the documentation for implementing push notifications for .net has not yet been described.

Regards, Nikita.

Ok, thank you, I will try it

Maria

Hi @Nikita_Fedorishchev ,
Finally I solved it in a different way.
Instead of launching another notification from CrossPushNotification.Current.OnNotificationReceived what I have done is to add the contentTitle that is in “android_inmediate_push” to the payload of the notification.

` CrossPushNotification.Current.OnNotificationReceived += (s, p) =>
    {
            System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", (String)p.Data["android_immediate_push"]);
           
            var values = JsonConvert.DeserializeObject<Dictionary<String, String>>((String)p.Data["android_immediate_push"]);
            p.Data.Add("title", values["contentTitle"]);
       
    };`

This way it shows me the correct title in the notification.

Thank you very much for your help :blush:
Maria

@Maria_Regil, awesome! I think this is a great solution and thank you. We will try to describe the connection of push notifications in .NET as soon as possible.

Best regards, Nikita.