android - 在 Android 上收不到推送通知

标签 android push-notification pushsharp

我没有收到我的 Android 推送通知。我可以

  • 注册设备
  • 接收设备标识符
  • 推送通知消息给GCM

我成功进入通知发送事件,但我的设备没有收到消息。推送成功代码如下:

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);

最佳答案

确保您已在 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

关于android - 在 Android 上收不到推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19124974/

相关文章:

c# - PushSharp 关注点分离

java - ScrollView 在其他内容下滚动

android - 如何在 Android DPM 中删除 set-device-owner?

安卓 Q : background activity starts

ios - iPhone 推送通知字数限制

Android 应用程序通过 FCM 获取推送通知但不显示消息

ios - 我可以使用 PushKit 进行定期推送而不使用 VoIP 吗?如果用户不根据通知采取行动,是否会允许在后台启动已终止的应用程序?

c# - Pushsharp 支持 Apple Push Notification Authentication Key

java - 类作为静态变量的容器

asp.net - 如何将 ASP.NET/PushSharp 项目转换为 Azure 以发送推送通知?