0

I am new to Push Sharp. I am trying to send messages to Android devices using Push Sharp. It works great but the problem is that Push Sharp is sending same message again and again.

My Code is:

AndroidPushBroker = new PushBroker();

var googleKey = CustomConfigurationManager.GetValueFromSection("appSettings", "GoogleServerAccessKey");
            AndroidPushBroker.RegisterGcmService(new PushSharp.Android.GcmPushChannelSettings(googleKey));

            var jsonMessage = "{\"InformationId\":\"" + notification.Message + "\",\"badge\":7,\"sound\":\"sound.caf\",\"NotificationType\":\"" + notification.Type.ToString() + "\"}";

            GcmNotification androidNotifcation = new GcmNotification().ForDeviceRegistrationId(notification.DeviceId)
                .WithJson(jsonMessage);
            AndroidPushBroker.QueueNotification(androidNotifcation);

Issue: When i send message "Message 1" and then later on send "Message 2", it sends "Message 1" again. Do I need to remove items from Queue ? Or what am I missing. ?

Note: I have single instance of Push Broker in my application.

Sumit
  • 2,932
  • 6
  • 32
  • 54

2 Answers2

0

I'm not very experienced with PushSharp either, but my guess is that you are not emptying the notification queue after sending your message.

Try to add the following after your QueueNotification call

AndroidPushBroker.StopAllServices();
frmi
  • 508
  • 1
  • 7
  • 21
0

Finally I got the issue. I was registering my gcm service again and again which was causing duplicate events.

AndroidPushBroker.RegisterGcmService(new PushSharp.Android.GcmPushChannelSettings(googleKey));

This should be called only once.

Sumit
  • 2,932
  • 6
  • 32
  • 54