I am developing a Windows 10 UWP application and I have a problem with raw notification sending and handling.
I am sending the notification from a server written in php, and when app is open I can receive the sent raw notification. Below is the template of my notification:
<toast launch='args'>
<visual>
<binding template = 'ToastGeneric'>
<text> başlık </text>
<text> Açıklama </text>
</binding>
</visual>
</toast>
I sent the template above as a raw notification.
Also, I am using the method below as backgroundtask
public void Run(IBackgroundTaskInstance taskInstance)
{
// Get the background task details
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
string taskName = taskInstance.Task.Name;
Debug.WriteLine("Background " + taskName + " starting...");
// Store the content received from the notification so it can be retrieved from the UI.
RawNotification notification = (RawNotification)taskInstance.TriggerDetails;
settings.Values[taskName] = notification.Content;
Windows.Data.Xml.Dom.XmlDocument doc = new XmlDocument();
var toast = new ToastNotification(doc);
var center = ToastNotificationManager.CreateToastNotifier();
center.Show(toast);
Debug.WriteLine("Background " + taskName + " completed!");
}
I set the task entry point in appmanifest, I could not test it with debugger.
I register the background task with the code below:
private void RegisterBackgroundTask()
{
BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
PushNotificationTrigger trigger = new PushNotificationTrigger();
taskBuilder.SetTrigger(trigger);
// Background tasks must live in separate DLL, and be included in the package manifest
// Also, make sure that your main application project includes a reference to this DLL
taskBuilder.TaskEntryPoint = SAMPLE_TASK_ENTRY_POINT;
taskBuilder.Name = SAMPLE_TASK_NAME;
try
{
BackgroundTaskRegistration task = taskBuilder.Register();
task.Completed += BackgroundTaskCompleted;
}
catch (Exception ex)
{
// rootPage.NotifyUser("Registration error: " + ex.Message, NotifyType.ErrorMessage);
UnregisterBackgroundTask();
}
}
Finally, my pushreceived event:
private async void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs e)
{
if (e.NotificationType == PushNotificationType.Raw)
{
e.Cancel = false;
Windows.Data.Xml.Dom.XmlDocument doc = new Windows.Data.Xml.Dom.XmlDocument();
var t = @" <toast launch='args'>
<visual>
<binding template = 'ToastGeneric'>
<text> başlık </text>
<text> Açıklama </text>
</binding>
</visual>
</toast> ";
doc.LoadXml(t);
var toast = new ToastNotification(doc);
var center = ToastNotificationManager.CreateToastNotifier();
center.Show(toast);
}
}
the inside of the method is only for testing.
Now, I want to ask that what is wrong or missin in my structure? Any suggession, example or help is appreciated.
Thanks in advance.