简体   繁体   中英

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.

I send the emails through SendGrid API,and I have setup an Azure Function webhook endpoint that gets called when the email is read.

I can attach a Notification Hub registration Id and a GCM Token to the emails which gets passed back to me via the 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?

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?

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.

I'd like to append implementation level knowledge.

Each individual can be managed by tag in Notification Hub as user can use multiple devices. Azure Notification Hub tag system is suitable to send a push for this situation. So, you could attach a tag like user:34939 to identify user (not to identify device).

For this reason, you should think that your requirement is to identify device or to identiy user . Whatever cases, GCM token does not have to be attached to email link. 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.

About template, yes. Template is required during registration.

FYI, tag has 120 character length limits. https://stackoverflow.com/a/21199385/361100

tagExpression in NotificationHub is dynamic. Please see Configuring notification tag for Azure Function for more details. Also, Azure functions now supports sending notificaitons to GCM registrations. You need to set the Notification Platform on the Binding to GCM.

Here is a sample for sending WNS push notification to a dynamic tag that comes in as queueTrigger:

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:

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

You can send GCM notifications by selecting GCM in Notification Platform.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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