Android 使用 Google 云消息传递和 Google App 引擎作为后端的推送通知
Android push notification with Google Cloud Messaging and Google App Engine as backend
我想将通知从 GAE 后端推送到 Android 应用程序。我已经通过 link 成功实现了通信:https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/GcmEndpoints
但是,我对这里的逻辑感到困惑。
- 在这个例子中,我们通过 AsyncTask 向 GCM 执行了客户端注册。我想在某些代码在 GAE 后端完成执行时通知用户,但不需要从 Android 调用一些 AsyncTask。我所需要的只是在这段代码完成执行时接收来自 GAE 的消息。这可能吗?我只是不知道这里的工作流程应该如何。
- 另外,客户端需要做什么才能"listen"接收新消息?某些始终在后台运行的服务任务?或者这是否已通过此示例中的
public class GcmIntentService extends IntentService
完成,我只需要识别消息类型?
如果有人能向我解释一下这个工作流程,还有一些代码示例也很好。
你真的应该通过 GCM guide,获得 GCM 运行 并不难,但它需要一系列不能跳过的步骤。
In this example, we have executed client registration to GCM, but via AsyncTask. I want to notify users when some code finishes execution on GAE backend, but without need to call some AsyncTask from Android
一个完整的 GCM 实现需要客户端注册到 GCM 服务器以获取其唯一 ID 并且您的服务器存储该 ID 以便直接联系该客户端,这就是为什么您需要至少一个连接来发送此数据到您的服务器。您可以通过使用一个名为 topics 的新功能来解决这个问题,这样一旦客户端注册,它就可以订阅一个主题,并且您的服务器不需要知道任何客户端的特定 GCM 密钥.我不推荐最后一种方法,因为它的可扩展性差,并且会禁用与您的服务器的任何一对一通信。
Also, what needs to be done on client side, so that it will "listen" for new messages? Some service task which always runs in background? Or is this already done with public class GcmIntentService extends IntentService from this example, and I just need to identify message type?
您需要设置一个广播接收器来处理您的应用程序的传入消息(指南中有详细说明),您可以从那里获取原始消息,您可以用它做任何您想做的事情,包括 运行通过意图服务,因为您直接在接收者上陈述或处理它(不推荐)。是的,您可以区分消息类型并相应地执行逻辑。
我想将通知从 GAE 后端推送到 Android 应用程序。我已经通过 link 成功实现了通信:https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/GcmEndpoints
但是,我对这里的逻辑感到困惑。
- 在这个例子中,我们通过 AsyncTask 向 GCM 执行了客户端注册。我想在某些代码在 GAE 后端完成执行时通知用户,但不需要从 Android 调用一些 AsyncTask。我所需要的只是在这段代码完成执行时接收来自 GAE 的消息。这可能吗?我只是不知道这里的工作流程应该如何。
- 另外,客户端需要做什么才能"listen"接收新消息?某些始终在后台运行的服务任务?或者这是否已通过此示例中的
public class GcmIntentService extends IntentService
完成,我只需要识别消息类型?
如果有人能向我解释一下这个工作流程,还有一些代码示例也很好。
你真的应该通过 GCM guide,获得 GCM 运行 并不难,但它需要一系列不能跳过的步骤。
In this example, we have executed client registration to GCM, but via AsyncTask. I want to notify users when some code finishes execution on GAE backend, but without need to call some AsyncTask from Android
一个完整的 GCM 实现需要客户端注册到 GCM 服务器以获取其唯一 ID 并且您的服务器存储该 ID 以便直接联系该客户端,这就是为什么您需要至少一个连接来发送此数据到您的服务器。您可以通过使用一个名为 topics 的新功能来解决这个问题,这样一旦客户端注册,它就可以订阅一个主题,并且您的服务器不需要知道任何客户端的特定 GCM 密钥.我不推荐最后一种方法,因为它的可扩展性差,并且会禁用与您的服务器的任何一对一通信。
Also, what needs to be done on client side, so that it will "listen" for new messages? Some service task which always runs in background? Or is this already done with public class GcmIntentService extends IntentService from this example, and I just need to identify message type?
您需要设置一个广播接收器来处理您的应用程序的传入消息(指南中有详细说明),您可以从那里获取原始消息,您可以用它做任何您想做的事情,包括 运行通过意图服务,因为您直接在接收者上陈述或处理它(不推荐)。是的,您可以区分消息类型并相应地执行逻辑。