android - 如何使用 GCM 向多个用户发送推送通知

标签 android .net google-cloud-messaging

我观看了一些演示,它在我的手机上运行良好。但我有一些问题。注册 ID 对于应用程序或用户来说是唯一的吗?如果它对用户来说是唯一的,那么如何在服务器(点网)中保存多个 regID。请给我一些指导。

最佳答案

If it is unique for user then how to save multiple regID's in server(dot net). Please give me some guidance.

当设备向 GCM 服务器注册时,设备必须将该唯一 ID 发送到您的服务器,然后您保存该值以用于发送消息。

How to send push notifications to multiple users using GCM?

您创建具有格式的消息。对于多个ID,只需将您的用户ID以数组对象的形式填入registration_ids

Python 示例:

ids=[]
query= // get all user record from database
for q in query:
    ids.append(q.registration_id)
// some code
jsonmessage=json.dumps({
    "registration_ids":ids,
    "data":{
        "message":message,
        "time":datetime.datetime.today().isoformat(),
        "sender":sender
     }
})
conn.send(jsonmessage)

看起来像这样:

Content-Type:application/json
Authorization:key=AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA
{
  "registration_ids" : ["APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...", "second_id", "third_id"],
  "data" : {
    ...
  },
}

关于android - 如何使用 GCM 向多个用户发送推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14229379/

相关文章:

android - youtube影片无法在android webview中运作

android - 如何在动态添加内容时使线性布局自动滚动

javascript - Android 版 Chrome 上的网络蓝牙未找到任何设备

android - GCM 演示不会在服务器和应用重启时接受消息

android - 如何在 android 中滚动时放大 Recycler View 中心项目?

c# - 无法在 asp.net core 的 startup.cs 文件中找到 Use.RunTimePageInfo() 方法

.net - SolrNet 查询不适用于斯堪的纳维亚字符

php - Firebase 推送通知不起作用获取 token 号但仍然不起作用

android - 无法实例化 GcmBroadcastReceiver

c# - 如何通过Linq查询MongoDB中的BsonExtraElements