Android 推送通知失败(注册无效)

Posted

技术标签:

【中文标题】Android 推送通知失败(注册无效)【英文标题】:Notification Failed (Registration Invalid) on an Android Push 【发布时间】:2015-06-02 14:56:55 【问题描述】:

我已成功向 ios 设备发送推送消息,但我遇到了 android 问题。我已获得 GCM API 密钥和已安装该应用的设备的注册 ID。

但是,当我尝试发送推送消息时,NotificationFailed 事件被触发。我得到的异常是PushSharp.Android.GcmMessageTransportResponse 类型,它的消息是“无效注册”。我到底做错了什么?

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

【问题讨论】:

【参考方案1】:

Android 推送通知需要 Google API 密钥,可以从 Google API 控制台找到,我假设您已经拥有。

您的设备注册 ID 很可能不正确。 请尝试按照以下说明操作:How to configure and send GCM push notification

【讨论】:

【参考方案2】:

这绝对是 API 密钥问题。检查您从开发者控制台获得的 API 密钥。它通常以“AIza...”开头

GCM 文档here 中提到了这个确切的错误。

【讨论】:

以上是关于Android 推送通知失败(注册无效)的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 Java GCM API 在 android 设备上获取失败推送通知的注册 ID

Firebase 会惩罚失败的推送通知吗?

APNS:无效令牌导致所有后续推送通知失败

iOS 推送通知注册失败

使用 curl 命令发送推送通知时出现无效注册错误

远程推送通知注册失败