I am trying to find a way to send a toast notification from a windows universal application. The Azure documentation does mention a way to do this from a Console Application. This does not meet my use case though, where I want to send toast notifications from a windows universal application. The problem is the nugget package Microsoft.Azure.Service.Bus is not compatible with a windows store or windows phone 8.1 application.
Is there any Windows Azure library that will allow me to send a toast notification from Windows universal application.
Typically you wouldn't send the toast from the Universal app. You would send the toast to the app to let the user know that something occurred on the server.
If you want to schedule a toast from the app to the local system then you don't need Azure (or another web service). You can schedule that directly with a scheduled notification. See Quickstart: Sending a toast notification (XAML) and How to schedule a toast notification (XAML)
If you want to push a notification elsewhere then you can set up an Azure Notification Hub and connect to it through its REST service via the HttpClient class.
More typically though your app would contact your back-end server to connect to the notification hub. This can be readily set up with an Azure Mobile Service. See Add push notifications to your Mobile Services app
Bellow two basics samples:
Sample 1 text only
const ToastTemplateType toastTemplate = ToastTemplateType.ToastText01;
var toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
var toastTextElements = toastXml.GetElementsByTagName("text");
toastTextElements[0].AppendChild(toastXml.CreateTextNode("Hello World!"));
var toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier().Show(toast);
Sample 2 text and image
const ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01;
var toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
var toastTextElements = toastXml.GetElementsByTagName("text");
toastTextElements[0].AppendChild(toastXml.CreateTextNode("Hello World!"));
var toastImageAttributes = toastXml.GetElementsByTagName("image");
((XmlElement)toastImageAttributes[0]).SetAttribute("src", "https://i.stack.imgur.com/wzdIt.jpg");
var toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier().Show(toast);
Toast notifications are small pop ups that appear on the screen for few seconds. They convey messages and can be customized to even play different sounds.
See the Windows Universal Apps notifications sample for more.
Related
I need advice after looking a lot about receive push/toast notifications regardless of the status of the application (closed or open).
The application communicates with a NodeJS API.
The idea is that a user logs in once to the application and then can receive notifications (depending on his account): i the user restarts his system for example, at startup he receives notifications without having to open the application (like the Mail application for example).
Most tutorials on MSDN use Azure and I don' use this. I would like to know if you have tips or links (tutorials, ...) for doing this in an UWP (or WinRT) application.
Thanks in advance for your help.
Regards
You can send push notifications from your NodeJS api via Windows Notification Service. This service has nothing to do with azure but when using Azure Notifications Hub it will be easier to get it implemented, but again this is not required;
In essence:
- register your app in dev center
- obtain a client id and client secret to use WNS in the dev center
- When your app launch it obtains a push notification channel uri and sends this to your backend. Your backend need to save all the URI's for the different devices
- When you have a notification select the uri's of the devices you want to send the push notification to
- post a xml message (based on what you want to update, tile, toast, badge or raw) to the URI's. To be able to post you need to authenticatie with the client id and client secret
more detailed read: https://msdn.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-windows-push-notification-services--wns--overview#
I am working on a Windows Phone 8.1 silverlight app, raw notifications handling.
The App when receives notifications in foreground, has to cancel the notification and create a new notification using ToastNotificationManager.CreateToastNotifier().
It also has a backgroundtask to work on the raw notifications received in background, which converts the raw notifications received to toast notification using ToastNotificationManager.CreateToastNotifier().
Also some action A needs to be performed on clicking of this notification.
The issue arises when the App receives the notification when in foreground, but the notification is clicked after suspending the application. Since the registered activated event of such type of notification is not in the background task (because the notification was formed in the foreground logic), no action A is performed on clicking of the notification.
This seems to a limitation, for WP8.1 silverlight apps. Can somebody suggest a solution for this issue??
If you need to do some action after tap on Toast you should add wp:Param to your Toast with deep url and handle in you app.
Toast will be look like
<wp:Notification xmlns:wp=\"WPNotification\">
<wp:Toast>
<wp:Text1>You title</wp:Text1>
<wp:Text2>Your subtitle</wp:Text2>" +
<!-- You can add any parameter you want in deep url -->
<wp:Param>/Page2.xaml?NavigatedFrom=Toast Notification</wp:Param>
</wp:Toast>
</wp:Notification>
When you tap on toast it by default will open Page2.xaml of your app and pass uri parameters to it
I want to send pushnotifications to windows phone.
string subscriptionUri = "https://hk2.notify.windows.com/?token=AwYAAAAqksei6yWvmlcV8RmESRNrXotwCWV0AY9PSOtmgpIo%2bNwq67tkYjG7450r%2bUKpLwxri%2bO7Re9%2f8qmZDAc3TmTlMOaONVqq9ogCKONX2oWe%2fVq%2bT9tIxEllJW3tnKJEfNM%3d";
//string subscriptionUri = "http://s.notify.live.net/u/1/hk2/H2QAAACfgMkOSS8jNp_XgLamnXFqQrk6g8L6pRJHsQxvppe8-lD4EgCu8LcwdtuDIGnY78tjyaL1lsFxLjWl5s-Sgum5tjBQMk-9emm73LJa9125iECyFCoPb5erRBRwGAgNv2o/d2luZG93c3Bob25lZGVmYXVsdA/jGFxihnYNUOIt5Q4gABT7Q/T4l1SvWZqMi_mEe4F61sx-CINOg";
in the above two channeluris first one is Windows RT app uri,second one is Silverlight app uri.Iam getting notification whenever silverlight app uri used.but I am not getting notification whenever windows RT app uri used.whenever
I am sending windows RT app uri to the server then response is "OK" but not getting any notification to my device.please help me.
Have you enabled toast notification? In Package.appxmanifest, Under Application tab there is "Notifications" option "Toast Capable" set it to "yes"
One more possibility is the subscription uri is getting decoded at the receiving end.
I want to send pushnotifications to windows phone.
string subscriptionUri = "https://hk2.notify.windows.com/?token=AwYAAAAqksei6yWvmlcV8RmESRNrXotwCWV0AY9PSOtmgpIo%2bNwq67tkYjG7450r%2bUKpLwxri%2bO7Re9%2f8qmZDAc3TmTlMOaONVqq9ogCKONX2oWe%2fVq%2bT9tIxEllJW3tnKJEfNM%3d";
//string subscriptionUri = "http://s.notify.live.net/u/1/hk2/H2QAAACfgMkOSS8jNp_XgLamnXFqQrk6g8L6pRJHsQxvppe8-lD4EgCu8LcwdtuDIGnY78tjyaL1lsFxLjWl5s-Sgum5tjBQMk-9emm73LJa9125iECyFCoPb5erRBRwGAgNv2o/d2luZG93c3Bob25lZGVmYXVsdA/jGFxihnYNUOIt5Q4gABT7Q/T4l1SvWZqMi_mEe4F61sx-CINOg";
in the above two channeluris first one is Windows RT app uri,second one is Silverlight app uri.Iam getting notification whenever silverlight app uri used.but I am not getting notification whenever windows RT app uri used.whenever
I am sending windows RT app uri to the server then response is "OK" but not getting any notification to my device.please help me.
Have you enabled toast notification? In Package.appxmanifest, Under Application tab there is "Notifications" option "Toast Capable" set it to "yes"
One more possibility is the subscription uri is getting decoded at the receiving end.
I am developing a simple windows phone 8 app using visual studio express 2012 and WP8 SDK using C# and SQLite. I would like to know how to send SMS or email to various recipients using this app with my windows phone (I do not want to send SMS through internet )
thanks a lotttt :)
You can't send an SMS or an email (from system account) without user approval. To do that use Launchers:
Email: Use EmailComposeTask: How to use the email compose task for Windows Phone
SMS: Use SmsComposeTask: How to use the SMS compose task for Windows Phone
They both shows popup and ask user to approve the message to be send.
in windows phone 8.1 i use the following code in C#:
ChatMessage chatMessage = new ChatMessage();
chatMessage.Body = "Text message";
chatMessage.Recipients.Add("phonenumber");
await ChatMessageManager.ShowComposeSmsMessageAsync(chatMessage);
Hope it helps :)