未在Android上接收推送通知

时间:2013-10-01 20:09:27

标签: android push-notification pushsharp

我没有收到Android推送通知。我能够

  • 注册设备
  • 收到设备标识符
  • 将通知消息推送至GCM

我成功进入Notification Sent事件,但我的设备上未收到任何消息。成功的推送代码如下:

string apiKey = "API KEY HERE";
push.RegisterGcmService(new GcmPushChannelSettings(apiKey));

string load = "Hello World";
int count = 2;
string dev = 'device identifier generated for device';
string payload = "{\"alert\":" + "\"" + load + "\"" + ",\"badge\":" + "\"" + count + "\"}";
//IMPORTANT: For Android you MUST use your own RegistrationId here that gets generated within your Android app itself!
GcmNotification note = new GcmNotification().ForDeviceRegistrationId(dev).WithJson(payload);

1 个答案:

答案 0 :(得分:1)

确保你在android端设置了所有内容。 https://developer.android.com/google/gcm/gcm.html

除此之外,PushSharp确实有一个你可能想要的新版本。 https://github.com/Redth/PushSharp

您可能还想添加一些事件来跟踪并确保没有问题。

        push.OnDeviceSubscriptionExpired += new DeviceSubscriptionExpiredDelegate(push_OnDeviceSubscriptionExpired);
        push.OnDeviceSubscriptionChanged += new DeviceSubscriptionChangedDelegate(push_OnDeviceSubscriptionChanged);
        push.OnChannelException += new ChannelExceptionDelegate(push_OnChannelException);
        push.OnNotificationFailed += new NotificationFailedDelegate(push_OnNotificationFailed);
        push.OnNotificationSent += new NotificationSentDelegate(push_OnNotificationSent);

然后在android端,检查logcat以查看是否有任何消息通过。

甚至退后一步,尝试从设备本身发送推送。 https://developer.android.com/google/gcm/client.html