使用Parse向单个设备发送推送通知

5

我能否通过我的Android应用程序向仅特定设备发送推送消息(可能使用设备ID?)而不是发送到每个设备?
一个简单的“是的,可以使用Parse实现”或“不,您不能使用Parse实现”就足够了!如果答案是肯定的,那么我需要知道如何实现.....

3个回答

9
您可以在ParseInstallation中保存设备ID,然后针对此安装进行目标定位。 接收器:
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("device_id", "1234567890");
installation.saveInBackground();

发送者:

ParseQuery query = ParseInstallation.getQuery(); 
query.whereEqualTo("device_id", "1234567890");    
ParsePush push = new ParsePush();
push.setQuery(query);
push.sendPushInBackground();

0
据我所知,您需要将发送设备/服务器的IP添加到Google控制台中,以便受信任 - 所以通常不会使用客户端向其他设备发送推送。相反,将消息发送到您的服务器,该服务器具有所有已注册到您的GCM令牌的设备,并让服务器将消息推送到特定客户端。
您应该阅读文档 http://developer.android.com/google/gcm/index.html

我想要从一个安卓设备发送消息到另一个设备...我将设备ID储存在Parse中...是的,我只想要发送文本消息。 - param
你需要拥有一个代理消息的服务器。如果你不想要这个,应该考虑使用短信替代。 - Daniel

0

设备 ID 是最佳选择。如果您想要向特定用户发送消息,请在 Parse 安装中创建一个附加字段,并将用户 ID 保存在此字段中,这样您就可以通过筛选 UserID 并设置查询以获取该特定用户的推送代码来向该特定用户发送消息。

ParseQuery query = ParseInstallation.getQuery(); 
query.whereEqualTo("device_id", "1234567890");   
query.equalTo("user_obj","your_user_object_here");
ParsePush push = new ParsePush();
push.setQuery(query);
push.sendPushInBackground();

你能否给我一些代码?接收端需要写什么吗? - Anand Phadke

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接