android - 为什么应用程序更新后要重新注册到 gcm?

标签 android push-notification google-cloud-messaging api-key

我在我的应用程序中使用 gcm。 在Google Developers Console页面中,我创建了一个项目并获取了项目id:

Google Developers Console Project Number image

在我的应用程序中使用此项目 ID,用户可以注册到 gcm 服务器并获得注册 ID。然后它被发送到我的第 3 方服务器进行存储。

当第 3 方服务器想要向用户发送消息时,它会使用我在 post 操作标题中的 Google 开发者控制台页面中获得的 apikey,并使用为此特定用户存储的注册 ID。我使用的 api key 来自:

Google Developers Console Page API key image

请注意,这是服务器应用程序的关键,我使用此信息的方式正如我所解释的那样。

一切正常,消息由正确的用户检索等等。我计划在 Google Play 上部署我的应用程序,但本节中写的是:GCM advanced topics让我困惑。它说:

When an application is updated, it should invalidate its existing registration ID, as it is not guaranteed to work with the new version

以及Implementing GCM client sample code中示例代码的注释部分有这样一条评论:

// Check if app was updated; if so, it must clear the registration ID
// since the existing regID is not guaranteed to work with the new
// app version.

这两种解释是什么意思?我想除非我在这里按重新生成键:

Google Developers Console Renegerate Key Image

我的 api key 不会改变。当我更新我的应用程序时,为什么它应该(或者确实)发生变化?还是我弄错了什么?

最佳答案

您正在混合使用两个不同的术语 - API key 和注册 ID。部署新版本时,您不必创建新的 API key 。

Google 建议(在上面引用的内容中)将安装新版本的每台设备重新注册到 GCM(而不是依赖之前获得的注册 ID),因为分配给 GCM 的现有注册 ID不保证您的应用程序的设备适用于新版本的应用程序。

关于android - 为什么应用程序更新后要重新注册到 gcm?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21741183/

相关文章:

java - 仅具有 https URL 时获取证书并将其添加到 Java 信任库?

android - GCM 如何处理带有 BroadCastReceiver 的应用程序

java - 创建 Android Intent 并指定目标 Activity 时,这个 ".class"语法是什么?

java - 使用按钮滚动后如何返回到 Activity 顶部?

android - Phonegap 多推送通知,当打开一个并返回时,它会从托盘中删除我的所有通知 - Android

android - 为什么通过 pushwoosh 通知点击打开 Activity 在 android 中不起作用?

java - 不幸的是(应用程序)已停止 Android 开发者错误

android - 如何在 fragment 中创建 editText

android - HMS+GMS 设备上的 HMS 推送通知问题

java - 应用程序不会收到消息并通过 GCM 获得 "NotRegistered"响应