0

This may seem like an odd question, but is there a way to send a local toast notification from a Windows 8 Store App to the machine--and NOT show it on the screen? I have a background task that needs to send a sync request to the UI thread. I have been searching for the better part of 8 hours trying to get different methods to work--and it comes down to this will work for me, but I don't want the request text to show up on the screen when I call it.

I should also add that Toast Notifications WILL be used in the app, so I can't simply turn it off globally, I need only the ones I specify to not show up, to be hidden. Is this possible?

Ideally, I would rather do a Raw Notification, but I can't figure out how to do a local Raw Notification (of if its even possible to simulate it without hitting my API.).

EDIT: Root Problem My background task is doing work behind the scenes every 15 minutes--to basically send a sync request to the main app. The OnPushNotificationReceived, should capture this and perform a full sync of all data I need: Such as GPS coordinates, checking if "ToDoItems" are nearing due dates and need to be escalated in priority, etc. Among other things, such as checking if there are any documents on the local file system that have been marked as complete and need to be uploaded to Azure file storage, etc.

MorpheusZero
  • 199
  • 14
  • What's the root problem? Maybe there are other solutions. – Ilian Jan 18 '16 at 23:30
  • Edited with a bit more info for my situation. – MorpheusZero Jan 18 '16 at 23:39
  • Is your background task running on another application or from a server? I don't get why you can't just dispatch a message to the UI thread directly without going through toast notifications. – Ilian Jan 19 '16 at 02:14
  • The background task is running from the application itself--I just don't know how to implement what you mean. I've never worked with threading or background tasks before. I'm trying to clone what I found in the MSDN sample project for background tasks right now. Hopefully it works. – MorpheusZero Jan 19 '16 at 15:40
  • Why don't you do what you need in a background task itself? – Alex Sorokoletov Jan 22 '16 at 14:59
  • Unfortunately, I am using Azure Mobile Services to connect to a local SQLite database. I do not have access to my SyncContext from within the Background Task. I have followed a few tutorials to add this, but none of them work correctly. None of the NuGet packages I need will work with one another. If I get the Azure references, then my JSON.NET is incompatible.. This is also for Azure.Storage, when I use that, my SQLite PCL isn't compatible. I can't figure out how to make everything I need work. So for now, I'm using the BG Task as a glorified timer, and running all the code in the UI Thread. – MorpheusZero Jan 27 '16 at 19:18

1 Answers1

1

The answer might be in the OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args)

args.Cancel = true

From MSDN: https://msdn.microsoft.com/en-us/library/br241295
Cancel: Read/write Gets or sets whether Windows should perform its default handling of the notification.

You receive the notification and process it in your OnPushNotificationReceived listener, set the cancel to true and voila!
Basically you already processed the notification, so you cancel the default behaviour that is showing the notification.

EDIT CONTENT: The Raw Notification basically is an empty envelope where you can put any content in any form you want, could be an object, an image, a dictionary... Basically you decide the content to send and obviously the app must know the datamodel to be able to process it.

To create Notifications easily I recommend you this Nuget Package: https://github.com/WindowsNotifications/NotificationsExtensions/tree/master/Windows%208.1%20RT

Example on how to create a toast notifcation:

var toastNoti = ToastContentFactory.CreateToastText02();
toastNoti.TextHeading.Text = "TEXT IN BOLD";
toastNoti.TextBodyWrap.Text = "TEXT IN NORMAL CASE ";
toastNoti.Launch = "NOTIFICATION ARGUMENTS";    
var doc = new XmlDocument();
doc.LoadXml(toastNoti.ToString());
var endNotification = new ToastNotification(doc);
endNotification.Tag = "1";
ToastNotificationManager.CreateToastNotifier().Show(endNotification);

Hope this helps. Tell us any result please.

Arys
  • 477
  • 3
  • 12