0

在 Android 应用程序上,如何获取注册 ID?

4

2 回答 2

2

来自 C2DM 文档

这是在移动设备上运行的 Android 应用程序注册以接收消息时发生的事件序列:

  • 当应用程序第一次需要使用消息服务时,它会触发一个注册 Intent 到 C2DM 服务器。这个注册Intent(com.google.android.c2dm.intent.REGISTER)包括sender ID(即授权给应用发送消息的账号,一般是应用开发者设置的账号的邮箱地址) ,以及应用程序 ID。

  • 如果注册成功,C2DM 服务器会广播一个 REGISTRATION Intent 给应用程序一个注册 ID。应用程序应存储此 ID 以供以后使用。请注意,Google 可能会定期刷新注册 ID,因此您应该在设计应用程序时理解 REGISTRATION Intent 可能会被多次调用。您的应用程序需要能够做出相应的响应。

  • 为了完成注册,应用程序将注册 ID 发送到应用程序服务器。应用程序服务器通常将注册 ID 存储在数据库中。注册 ID 会一直持续到应用程序明确取消注册,或者直到 Google 为您的应用程序刷新注册 ID。
于 2011-05-12T07:20:08.923 回答
0

这是 C2DM 页面的链接。http://code.google.com/android/c2dm/index.html#registering

在页面底部有一个使用 C2DM 的示例应用程序的链接。

基本上你需要声明一个接收者来接收来自谷歌的registration_id,然后像这样启动一个注册请求:

Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); // boilerplate
registrationIntent.putExtra("sender", emailOfSender);
startService(registrationIntent);
于 2011-05-12T08:27:35.653 回答