0

I have succeeded sending a push message to an iOS device but I'm running into problem with Android. I have been given the GCM API key and the registration id of the device that has the app installed.

However, when I try to send the push message, the NotificationFailed event is triggered. The Exception I get is of type PushSharp.Android.GcmMessageTransportResponse and its message is "Invalid Registration". What is it that I am doing wrong?

var push = new PushBroker();
push.OnNotificationSent += NotificationSent;
push.OnChannelException += ChannelException;
push.OnServiceException += ServiceException;
push.OnNotificationFailed += NotificationFailed;
push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
push.OnChannelCreated += ChannelCreated;
push.OnChannelDestroyed += ChannelDestroyed;

push.RegisterGcmService(new GcmPushChannelSettings("AIXXXXXXXXXXXXXXXX"));
push.QueueNotification(new GcmNotification()
             .ForDeviceRegistrationId("APAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
.WithJson("{\"alert\":\"Hello World!\",\"badge\":7,\"sound\":\"sound.caf\"}");
push.StopAllServices();
disasterkid
  • 6,948
  • 25
  • 94
  • 179

2 Answers2

1

Push Notification for Android require Google API Key, which could be found from Google APIs console, which I assume you already have.

Most likely your device registration id is incorrect. Try following these instructions: How to configure and send GCM push notification

Sparkle
  • 681
  • 5
  • 10
1

This is most definitely an API key issue. Check the API key that you got from the Developers Console. It usually starts with "AIza..."

This exact error is mentioned in the GCM docs here.

Koh
  • 1,570
  • 1
  • 8
  • 6