简体   繁体   English

从Android进行Azure通知中心注册

[英]Azure Notification Hub Registration from Android

I am trying to send a Push Notification with a text that says "Email Read" to individual users when the email they send through my Android App is read. 当我阅读个人用户通过我的Android应用发送的电子邮件时,我尝试向其发送带有“已读电子邮件”文本的推送通知。

I send the emails through SendGrid API,and I have setup an Azure Function webhook endpoint that gets called when the email is read. 我通过SendGrid API发送电子邮件,并且已设置一个Azure Function webhook终结点,该终结点在读取电子邮件时会被调用。

I can attach a Notification Hub registration Id and a GCM Token to the emails which gets passed back to me via the webhook. 我可以将Notification Hub注册ID和GCM令牌附加到电子邮件中,并通过Webhook传递回给我。

Armed with the GCM Token, I know the device/individual I want to send the notification to, my challenge now is how do I call Azure Notification Hub to target individual user? 有了GCM令牌,我知道要将通知发送到的设备/个人,我现在面临的挑战是如何调用Azure Notification Hub来针对单个用户?

Currently Azure Function only support Notification Hub binding with Templating, and that brings me to yet another challenge, how can I register for Azure notification hub from Android device using an installation? 当前,Azure Function仅支持将Notification Hub与模板绑定,这给我带来了又一个挑战,如何使用安装从Android设备注册Azure Notification Hub?

I haven't tried this myself, but here's what I think you would need: 我自己还没有尝试过,但是我认为这是您需要的:

Refer to Registration management post for more information about installation model. 有关安装模型的更多信息,请参考注册管理文章。

@Nikita G. guides correctly in overall. @Nikita G.总体上正确引导。

I'd like to append implementation level knowledge. 我想附加实施级别的知识。

Each individual can be managed by tag in Notification Hub as user can use multiple devices. 每个用户都可以通过Notification Hub中的tag进行管理,因为用户可以使用多个设备。 Azure Notification Hub tag system is suitable to send a push for this situation. Azure Notification Hub标记系统适合在这种情况下发送推送。 So, you could attach a tag like user:34939 to identify user (not to identify device). 因此,您可以附加一个类似于user:34939的标签来标识用户(而不是标识设备)。

For this reason, you should think that your requirement is to identify device or to identiy user . 因此,您应该认为您的要求是识别device或识别user Whatever cases, GCM token does not have to be attached to email link. 无论哪种情况,都不必将GCM令牌附加到电子邮件链接。 Only tag value (userid) is enough to identify user or only Hub registration id is enough to identify device. 仅标记值(用户标识)足以标识用户,或者仅集线器注册标识足以标识设备。 The Hub registration id helps to manage registered devices regardless of APNS or GCM token. 集线器注册ID有助于管理注册的设备,而不考虑APNS或GCM令牌。

About template, yes. 关于模板,是的。 Template is required during registration. 注册期间需要模板。

FYI, tag has 120 character length limits. 仅供参考,标签有120个字符长度限制。 https://stackoverflow.com/a/21199385/361100 https://stackoverflow.com/a/21199385/361100

tagExpression in NotificationHub is dynamic. NotificationHub中的tagExpression是动态的。 Please see Configuring notification tag for Azure Function for more details. 有关更多详细信息,请参见为Azure功能配置通知标记 Also, Azure functions now supports sending notificaitons to GCM registrations. 此外,Azure功能现在支持向GCM注册发送通知。 You need to set the Notification Platform on the Binding to GCM. 您需要在“绑定到GCM”上设置“通知平台”。

Here is a sample for sending WNS push notification to a dynamic tag that comes in as queueTrigger: 这是用于将WNS推送通知发送到作为queueTrigger出现的动态标签的示例:

function.json function.json

{
  "bindings": [
   {
     "name": "myQueueItem",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "test-queue",
      "connection": "AzureWebJobsDashboard"
    },
    {
       "type": "notificationHub",
       "name": "notification",
       "hubName": "youthubname",
       "connection": "NOTIFICATIONHUB_AppSettingName",
       "direction": "out",
       "tagExpression": "{userIdTag}",
       "platform": "wns"
     }
   ],
   "disabled": false
}

C# QueueTrigger: C#QueueTrigger:

using System;

public static void Run(PushToTag myQueueItem, TraceWriter log, out string    notification)
{
    log.Info($"C# Queue trigger function processed: {myQueueItem.UserIdTag}");
    notification = "<toast><visual><binding template=\"ToastText01\"><text  id=\"1\">Test message</text></binding></visual></toast>";
}

public class PushToTag
{
     public string UserIdTag { get; set; }
     public string UserName { get; set; }
}

Sample Queue Data 样本队列数据

{"UserIdTag":"tag1" , "UserName":"joe"}

Note: tag1 is the tag registered by the client 注意:tag1是客户端注册的标签

You can send GCM notifications by selecting GCM in Notification Platform. 您可以通过在Notification Platform中选择GCM来发送GCM通知。

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

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