Reputation: 7278
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();
Upvotes: 0
Views: 2024
Reputation: 1570
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.
Upvotes: 1
Reputation: 689
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
Upvotes: 1