【问题标题】:Sending a link using push notifications in Azure for Android在适用于 Android 的 Azure 中使用推送通知发送链接
【发布时间】:2017-08-15 13:50:27
【问题描述】:

我在 asp.net web-forms 中创建了一个支持,成功为所有注册设备发送通知,但我厌倦了发送链接,例如我需要发送一个推送通知,包括一个链接当用户触摸通知重定向到移动浏览器并打开链接。

 private static async void SendNotificationAsync()
        {
            NotificationHubClient hub = NotificationHubClient
                .CreateClientFromConnectionString("<Here is my endpoint >", "<hub name>");

            await hub.SendGcmNativeNotificationAsync("{ \"data\" : {\"message\":\"Hello Users \"}}");

        }

【问题讨论】:

    标签: firebase-cloud-messaging azure-notificationhub android-push-notification


    【解决方案1】:

    根据我的经验,我们可以使用自定义 json 格式,并在接收端将该字符串转换为 url。例如,下面是一个完整的 JSON 有效负载示例,其中包含包含 URL 的自定义“web_link”键:

     {"data": "{\"message\":\"xxxx\",\"web_link\":\"https://www.example.com\"}"}
    

    然后我们可以重写OnMessage函数来创建通知,我们也可以从Azure document获取更多详细信息。

    【讨论】:

    • 尊敬的 Tom Sun,当我从 Azure 门户发送它时,显示错误通知无法发送测试消息。错误:{"readyState":4,"responseText":"{\"error\":{\"message\":\"Bad Request\",\"code\":\"BadRequest\"}}", "responseJSON":{"error":{"message":"Bad Request","code":"BadRequest"}},"status":400,"statusText":"Bad Request"}。发送测试消息失败。错误:{"readyState":4,"responseText":"{\"error\":{\"message\":\"Bad Request\",\"code\":\"BadRequest\"}}", "responseJSON":{"error":{"message":"Bad Request","code":"BadRequest"}},"status":400,"statusText":"Bad Request"}。相关事件
    • 请尝试在消息中包含自定义格式的 url。例如:{"data": "{\"message\":\"xxxx--url\"}"}。我还更新了 json 文件
    • 当用户点击移动设备网络浏览器中打开的链接时,我想发送一个链接
    • 对不起,我不是移动专家,但我找到了另一个SO thread 参考这个。希望有用。
    • 我也没有问题,感谢您回答 Tom Sun。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-29
    • 2019-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多