gpt4 book ai didi

不同设备的Android重复注册ID

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:01:09 27 4
gpt4 key购买 nike

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

我看到了这个帖子,但那里似乎没有答案: Can two different devices have same GCM Registration 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);

最佳答案

我想到的唯一想法是,如果 sender 的额外值在所有设备上都相同,则此已弃用的方法将在不同设备上分配相同的 ID。这与当前版本不同,在当前版本中,您不说自己是谁,甚至不发送 Intent,您只需调用 register(),Google 就会确定您是谁是什么,应该给你什么 ID。

如果您最终使用了这个新库,这里有一个如何注册的示例 fragment (在 AsyncTaskThread 中):

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

关于不同设备的Android重复注册ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22101402/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com