GCM发送消息给特定的用户 [英] Send GCM message to Particular user

查看:128
本文介绍了GCM发送消息给特定的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我想通知发送到特定用户无关的设备。 用户可以登录到任何设备的应用程序。

In my application i want to send notification to a particular user irrespective of the device. User can log into the application from any device.

这是我第一次使用GCM。我的理解是说,当与GCM服务器注册的设备,该设备发送的唯一ID服务器,然后再保存该值发送消息的文档。

This is the first time i am using GCM. I read the document it says that when the device registered with the GCM server, the device send that unique ID to the server, and then save that value for sending messages.

那么如何通知发送到特定的用户,当他登录到不同设备上的应用程序?

Then how to send notification to a particular user when he log into the application from different devices?

推荐答案

这唯一的ID(即注册ID)是唯一的给定应用程序/设备,因此,如果在其他设备上该用户登录到GCM服务,它​​会产生另一个注册ID

This unique ID (aka registration ID) is unique given an app/device, so if this user logs to GCM services on another device it will generate another registration ID.

在GCM服务器到Android应用程序,允许它接收消息发出的ID。一旦Android应用程序具有的注册ID ,将其发送至第三方应用服务器,,它使用它来识别已注册接收消息对于给定的Andr​​oid应用程序的每个设备。换句话说,一个注册ID绑定到特定的设备上运行特定的Andr​​oid应用程序。

An ID issued by the GCM servers to the Android application that allows it to receive messages. Once the Android application has the registration ID, it sends it to the 3rd-party application server, which uses it to identify each device that has registered to receive messages for a given Android application. In other words, a registration ID is tied to a particular Android application running on a particular device.

当你说登录我觉得你的定做到您的服务器,对吧?

When you say log I think you are reffering to your server, right?

我问它,因为GCM服务需要一个谷歌帐户,如果您的应用程序目标定位pre 4 API的版本。

I ask it because GCM services requires a Google account if your app is targetting pre 4 API versions.

一个谷歌帐户不是在运行Android 4.0.4或更高版本的设备的要求。

A Google account is not a requirement on devices running Android 4.0.4 or higher.

如果GCM检测设备就可以查看在该服务上的一个谷歌帐户。 如果GCM没有检测到帐户它返回一个错误ACCOUNT_MISSING

If GCM detects a google account on the device it can acces to the service. If GCM does not detect the account it returns an ACCOUNT_MISSING error.

因此​​,它可能发生在同一个谷歌帐户,是不是你的,如果你正在使用其他设备这与一个谷歌帐户pviously注册$ P $存取权限的GCM服务。

So it could happen to acces the GCM services with a google account that is not yours if you are using another device which was previously registered with a Google account.

但是,如果重要的帐户是一款由服务器管理的话,我想这并不重要。

But if the important account is one managed by your server then I think it does not really matter.

更新:

您必须将通知发送到属于连接到服务器的用户的所有registrationID。你可以不知道哪些设备正在使用,如果你十个分量多个在您的服务器的用户。

You will have to send the notification to all registrationID belonging to the user connected to your server. You can not know which device is the user currently using if you mantain more than one at your server.

您可以使用多播

参考:GCM

这篇关于GCM发送消息给特定的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆