18. //get the gcm id
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String gcmid = gcm.register(SENDER_ID);
//instantiate a new NotificationHub instance
NotificationHub hub = new NotificationHub("<hub name>", "<connection
string>", context);
//register with the NotificationHub
NativeRegistration r = hub.register(gcmid);
19. //instantiate a new instance of NotificationHubClient
var hubClient =
NotificationHubClient.CreateClientFromConnectionString("<connection
string>", "<hub name>");
//create the json payload for the notification
var payload = "{ "data" : {"msg":"Hello from Windows Azure!"}}";
//send notification via gcm
hubClient.SendGcmNativeNotificationAsync(payload);
20. No need to store and maintain gcmId.
Device registrations expire.
23. //get the gcm id
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String gcmid = gcm.register(SENDER_ID);
//instantiate a new NotificationHub instance
NotificationHub hub = new NotificationHub("<hub name>", "<connection
string>", context);
//register with the NotificationHub using tags
NativeRegistration r = hub.register(gcmid, "Beatles");
24. //instantiate a new instance of NotificationHubClient
var hubClient =
NotificationHubClient.CreateClientFromConnectionString("<connection
string>", "<hub name>");
//create the json payload for the notification
var payload = "{ "data" : {"msg":"Hello from Windows Azure!"}}";
//create a list of tags
var tags = new List<string>(){ "Beatles" };
//send notification to devices registered with tags via gcm
hubClient.SendGcmNativeNotificationAsync(payload, tags);
32. //get the gcm id
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String gcmid = gcm.register(SENDER_ID);
//instantiate a new NotificationHub instance
NotificationHub hub = new NotificationHub("<hub name>", "<connection
string>", context);
//create the template
String template = "{ "data" : {"msg":"$(message)"}}";
//register with the NotificationHub using the template
NativeRegistration r = hub.register(gcmid, "Template1", template, "Beatles");
33. //instantiate a new instance of NotificationHubClient
var hubClient =
NotificationHubClient.CreateClientFromConnectionString("<connection
string>", "<hub name>");
//create expressions to substitute in the template
var expressions = var Dictionary<string, string>();
expressions.Add("message", "hello");
//send template notification to all devices
hubClient.SendTemplateNotificationAsync(expressions);
34.
35.
36.
37.
38.
39. What Next?
Try it out. For Free.
Build what you want. Scale as you need. Full access with no strings
attached.
http://aka.ms/thecloud
Hello startups!
You have an ideas so brilliant it burns. BizSpark can help make it real.
http://aka.ms/JoinBizSpark or CONTACT ME!