- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 GoogleCloudMessaging 在我的应用中实现通知功能。但我有一个问题,当我卸载我的应用并重新安装时,我得到了2 个不同的注册 ID,这导致向我的应用发送重复通知 .
在the document ,他们说:“重复调用此方法将返回原始注册 ID”
public String register (String... senderIds)
Register the application for GCM and return the registration ID. You must call this once, when your application is installed, and send the returned registration ID to the server.
Repeated calls to this method will return the original registration ID.
但是在another document ,他们想出了一个叫做“Canonical IDs”的东西:
Canonical IDs On the server side, as long as the application is behaving well, everything should work normally. However, if a bug in the application triggers multiple registrations for the same device, it can be hard to reconcile state and you might end up with duplicate messages.
那么我怎样才能使它在所有设备上保持一致呢?我的(第三方)服务器仅存储注册 ID,这些 ID 将用于发送通知。现在,“规范 ID”来了,一切都变得如此复杂!
这是否意味着我必须在注册时为每个设备发送一个唯一的标识号?
这是我用来将设备注册到 GoogleCloudMessaging 的代码块:
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(context);
}
regid = gcm.register(SENDER_ID);
Log.d(TAG, "########################################");
Log.d(TAG, "Current Device's Registration ID is: " + regid);
Map<String, String> data = new HashMap<String, String>();
data.put("regId", regid);
try {
Utils.post(Constants.SERVER_NOTIFY_REG_LINK, data);
Log.d(TAG, "ID registered: " + regid);
} catch (Exception e) {
e.printStackTrace();
}
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
Log.d(TAG, msg);
}
最佳答案
是的,在重新安装后注册该应用程序可能会为您提供一个新的注册 ID。您可以在服务器端或客户端处理它:
客户端:为应用程序的每个实例分配一个唯一的实例 ID。将该 ID 存储在外部存储中,以便在卸载应用程序时不会将其删除。将该 ID 与注册 ID 一起发送到您的服务器,如果您在数据库中发现与同一实例 ID 关联的旧注册 ID,则将旧注册 ID 替换为新注册 ID。
服务器端:每当您从 GCM 的响应中获得规范注册 ID 时,请从您的数据库中删除旧注册 ID(如果规范注册 ID 不在您的数据库中,则插入规范注册 ID)。
我建议你两者都做,因为第二个只能在你收到重复消息后解决问题,而第一个不是完整的证明(因为外部存储可能被删除或不可用)。
关于android - GoogleCloudMessaging#register 在同一应用程序/设备中返回不同的 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26030387/
我正在尝试在我的项目中实现 gcm,因为我想制作设备到设备的消息传递应用程序 我在这里阅读 http://developer.android.com/google/gcm/client.html因为它
正如问题所说,如何找出 registration ID 何时执行?已在 GoogleCloudMessaging 中失效应用程序接口(interface)?我已经阅读了关于类似主题的几个问题的答案:D
我需要在我的应用中使用 GoogleCloudMessaging。我通过 Cocoapods 安装了它。当我添加这部分代码时: GLInstanceIDConfig *instanceIDConfig
我是世界上唯一遇到此问题的人。所以我认为我真的需要一位专家。 我正在使用 Eclipse 和 Android 开发工具。 我已将所有相关库添加到项目中 我已经添加了 gcm.jar GoogleClo
我正在使用 Google Cloud Messaging在我的应用程序中借助 Urban Airship。 Urban Airship 正在向 GCM 注册,我的代码正在接收 GCM 消息。 我的问题
我试图在 Android 应用程序中实现推送通知,我发现了很多示例,但它们都导入了 com.google.android.gcm - 一个已被弃用的包 (据推测)它的功能包含在 GooglePlayS
我尝试从 gcm.jar 更新以从 google-play-services.jar 获取 GCM。我使用与所示相同的代码 here . 我使用的是与更改客户端实现之前相同的服务器 (node-gcm
我知道有很多帖子有同样的问题,但看完所有帖子后我找不到问题的原因。 我编写了一个 GCM 客户端来注册我的设备以从我的服务器接收消息。它正在运行,我可以将注册 ID 存储在我的数据库中。 我的问题出在
是否可以借助 robolectric 对 GCM 上游消息进行单元测试?这是我的单位: public void sendUpstream(Bundle data) { GoogleCloudM
我正在尝试让 GCM 在我的应用程序中运行(以在我们的营业时间更改或我们有任何促销 Activity 时通知用户),但我不断收到错误 无法解决尝试使用 Google Cloud Messaging A
我已经使用 Google Cloud Messaging 创建了 TokenID。 在我的 app 中有一个启用和禁用 Notification 的选项。 如果我使用 GoogleCloudMessa
我正在尝试从我的应用程序类 Global 中调用 Google Cloud Messaging 的注册操作: Global global; global = new Global();
我对 Java 编程和一般编程还很陌生。现在我决定制作我自己的应用程序,该应用程序应该使用谷歌云消息传递。不知何故我成功了,但后来我意识到我使用了方法 String regid = gcm.regis
我遇到了 android 应用程序所说的问题。 “The application xxxx Sorry stopped”与推送通知一起工作,当执行调试器时发生在它通过时: 方法一 InstanceID
我正在尝试发帖到 Googles Cloud Messaging Api (GCM) ,但我的请求失败,响应为 HTTP/1.1 400 InvalidTokenFormat。 但是,如果我更改程序,
最近,我注意到,Google 通过使用 google play service SDK,准确地说是 GoogleCloudMessaging 类,为 GCM 提供了新方法。我在 Google Code
我正在尝试使用 GCM 向设备发送消息。作为一种特殊情况,我使用 android 设备作为我的第三方服务器。我添加了以下代码,但出现“Unauthorized Error 401”。在这里,我只是想在
我正在使用 gcm 描述的新方法 here使用 GoogleCloudMessaging 类。但是 10 次中有 9 次出现 SERVICE_NOT_AVAILABLE 错误。只有一次它注册了一个设备
这个问题在这里已经有了答案: Is there any reason to continue using IntentService for handling GCM messages? (1 个回
你好,我正在按照 android 的官方文档发送推送通知,因为旧方法已被弃用,但我在实现 GCM 客户端时遇到问题 http://developer.android.com/google/gcm/cl
我是一名优秀的程序员,十分优秀!