几个小时后,Android SDK 从 GCM 收到 NotRegistered 错误 [英] Android SDK gets NotRegistered error from GCM after a few hours
问题描述
我正在编写 Android SDK,它应该从 SDK 服务器端接收 GCM 推送消息.推送消息成功发送几个小时后,GCM 服务器返回 NotRegistered
错误:
I am writing and Android SDK which should receive GCM push messages from the SDK server side. After a few hours of successful push message sending, the GCM server returns an NotRegistered
error:
{
"multicast_id":6205350692941230304,
"success":0,
"failure":1,
"canonical_ids":0,
"results":
[
{
"error":"NotRegistered"
}
]
}
客户端的registrationId
没有改变,服务端用那个token更新了.
The registrationId
at the client has not changed, and the server side is updated with that token.
如何解决 registrationId
问题?有两个监听器 - 一个在 SDK 中,一个在应用程序中 - 有问题吗?
How can I fix the registrationId
problem? Is having two listeners - one in the SDK, one in the app - a problem?
我的 Android SDK 在初始化时注册了一个 GCM regId
,并将该 id 发送到支持 SDK 的服务器.
My Android SDK registers a GCM regId
upon initialization, and sends that id to the server supporting the SDK.
包含应用程序可能(并且通常会)注册自己的 GCM regId
.另一个 regId
可能会发送到包含应用程序的服务器.
The embracing app might (and usually do) register a GCM regId
of its own. The other regId
is probably sent to the embracing app's server.
SDK和app的senderId
不同.
The senderId
of the SDK and app are different.
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> ...
<receiver
android:name="com.xxxx.xxxxx.xxxxx"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</receiver>
注册码
protected String doInBackground(Void... params) {
String msg = "";
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(mContext);
}
regid = gcm.register(SENDER_ID);
msg = "Device registered, registration ID=" + regid;
storeRegistrationId(mContext, regid);
listener.onGCMRegisterFinish(regid);
}
catch (IOException ex)
{
msg = "Error :" + ex.getMessage();
}
return msg;
}
此代码从 GCM 服务器获取 regId
并将其发送到我们的后端服务器.在SDK初始化时执行,每次后台返回时发送regId
.
This code gets the regId
from the GCM Server and send it to our backend server. It is executed at the SDK initialization, and the regId
is sent every time the app returns from background.
unregister()
不被调用,无论是从服务器端还是客户端- 我每隔一段时间就会用注册 id 举杯祝酒,所以我可以验证它在客户端和服务器之间是否相同:
unregister()
is not called, neither from server or client side- I am raising a toast with the registration id every once in a while, so I can verify it is the same between the client and the server:
2015-08-02 12:31:22,383 INFO - request_2145354041215926507
update push token for user: XXXXXXXX,
push_token: ...me1GttmSRipnWsCGVUueK7e0nk
推荐答案
使用你的包名添加 Category 到 intent-filter
Add Category with your package name to the intent-filter
<receiver
android:name=".xxxxx"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.xxxx" />
</intent-filter>
</receiver>
这篇关于几个小时后,Android SDK 从 GCM 收到 NotRegistered 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!