简体   繁体   English

Android GCM推送通知-将消息发送到一组设备

[英]Android GCM push notifications - sending messages to a set of devices

I have server which includes a database of usernames. 我有包含用户名数据库的服务器。 I also have an Android app in which users will register themselves a username with the server database, and also register the device with the GCM part of the server. 我也有一个Android应用程序,用户可以在其中向服务器数据库注册自己的用户名,并在服务器的GCM部分注册设备。

I am currently using the GCM demo in my server code, and it will multicast a push notification to every registered device. 我当前在服务器代码中使用GCM演示,它将向每个注册的设备多播一个推送通知。 However, I would like it so that push notifications are sent to certain users, not every registered GCM device. 但是,我希望将通知发送给某些用户,而不是每个注册的GCM设备。

My first idea was to associate each user in the database with their GCM regID. 我的第一个想法是将数据库中的每个用户与其GCM regID相关联。 Will this work? 这样行吗? I have read things about the regID changing or having duplicates, which makes it sound a somewhat unstable option for this purpose. 我已经阅读了有关regID更改或重复的内容,这使其听起来有点不稳定。

Any ideas on how I could achieve sending messages to certain devices would be appreciated. 关于如何实现将消息发送到某些设备的任何想法将不胜感激。

I may not fully understand your main concern, but here are a few thoughts. 我可能无法完全理解您的主要关注,但是这里有几点想法。

  • You are correct, the GCM RegistrationID can be changed by Google and it is your apps responsibility to update the server with a new RegistrationID. 您是正确的,Google可以更改GCM注册ID,并且使用新的RegistrationID更新服务器是您的应用程序的责任。
  • You certainly should associate the user in the database with their respective GCM RegistrationID since the likelihood of a user having more than one device is high. 您肯定应该将数据库中的用户与其各自的GCM注册ID相关联,因为用户拥有多个设备的可能性很高。
  • There should be no issue with screaming through the database and sending a message per User / per Device, but you will have to randomly pick the user/device combination if you only want to send a message only once to a user. 尖叫数据库并为每个用户/每个设备发送消息应该没有问题,但是如果您只想向用户发送一次消息,则必须随机选择用户/设备组合。

Again, not sure I understand your dilemma fully, but maybe this will help you think through possible solutions. 同样,不确定我是否完全理解您的困境,但这也许会帮助您思考可能的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM