Android重复注册ID为不同的设备

Orr*_*Orr 11 android push-notification google-cloud-messaging

我在推送通知服务器上看到此问题 - 不同的Android设备(由其IMEI标识)从Google的GCM服务接收SAME注册ID.注册ID不应该是唯一的吗?在东部为相同的应用程序或GCM API密钥?

我看到了这个帖子,但似乎没有答案: 两个不同的设备可以有相同的GCM注册ID吗?

任何帮助将非常感激

编辑 这里是注册的相关代码:

 Intent intent = new Intent(
                                   "com.google.android.c2dm.intent.REGISTER");
                   intent.setPackage("com.google.android.gsf");
                   intent.putExtra("app",
                                   PendingIntent.getBroadcast(context, 0, new Intent(), 0));

                   intent.putExtra("sender", flatSenderIds);
                   context.startService(intent);
Run Code Online (Sandbox Code Playgroud)

nKn*_*nKn 6

我想到的唯一想法是,如果sender所有这些方法的额外值相同,则不推荐使用的方法将在不同的设备上分配相同的ID .这与当前版本不同,你不会说你是谁,你甚至不发送Intent,你只是打电话register(),谷歌确定你是谁,你应该给出什么ID.

如果你最终使用这个新库,那么有一个如何注册的示例片段(在一个AsyncTask或一个内部Thread):

GoogleCloudMessaging gcm = null;

try {
  // Will be for the first time
  if (gcm == null)
    gcm = GoogleCloudMessaging.getInstance(your_context);

  // Registration against the GCM service
  String regid = gcm.register(YOUR_SENDER_ID_OBTAINED_FROM_YOUR_PROJECT);

  // You'll need to send the registration info to your remote server
  registerRemoteServer(regid);

  Log.d("MyGCM", "Registered on GCM as " + regid);
}
catch (final IOException ex) { ex.printStackTrace(); }
Run Code Online (Sandbox Code Playgroud)


M D*_*M D 5

有时Google会更改注册ID,您将拥有多个ID.发送通知的服务器(您的服务器)必须使用新ID更新数据库.

有关更多信息,请查看此文档:

http://developer.android.com/google/gcm/adv.html

他们说:

这是Canonical ID

在服务器端,只要应用程序运行良好,一切都应该正常工作.但是,如果应用程序中的错误触发同一设备的多个注册,则可能很难协调状态,并且最终可能会出现重复的消息.

GCM提供了一个名为"规范注册ID"的工具,可以轻松地从这些情况中恢复.规范注册ID定义为应用程序请求的最后一次注册的ID.这是服务器在向设备发送消息时应使用的ID.

如果稍后您尝试使用不同的注册ID发送消息,GCM将照常处理请求,但它将在响应的registration_id字段中包含规范注册ID.确保使用此规范ID替换存储在服务器中的注册ID,因为最终您使用的ID将停止工作.