c# windows 10 raw notification when app is CLOSED -


i developing windows 10 uwp application , have problem raw notification sending , handling.

i sending notification server written in php, , when app open can receive sent raw notification. below template of notification:

           <toast launch='args'>                 <visual>                     <binding template = 'toastgeneric'>                          <text> başlık </text>                          <text> açıklama </text>                         </binding>                     </visual>             </toast>  

i sent template above raw notification.

also, using method below backgroundtask

public void run(ibackgroundtaskinstance taskinstance)     {         // background task details         applicationdatacontainer settings = applicationdata.current.localsettings;         string taskname = taskinstance.task.name;          debug.writeline("background " + taskname + " starting...");          // store content received notification can retrieved 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 task entry point in appmanifest, not test debugger.

i register background task code below:

 private void registerbackgroundtask()     {         backgroundtaskbuilder taskbuilder = new backgroundtaskbuilder();         pushnotificationtrigger trigger = new pushnotificationtrigger();         taskbuilder.settrigger(trigger);          // background tasks must live in separate dll, , included in package manifest         // also, make sure main application project includes reference 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, 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 method testing.

now, want ask wrong or missin in structure? suggession, example or appreciated.

thanks in advance.

did check in manifest declarations have checked "push notifications"?

also need @ top registerbackgroundtask method call

await backgroundexecutionmanager.requestaccessasync(); 

here documentation https://msdn.microsoft.com/pl-pl/library/hh700494.aspx important sentence "requests app permitted run background tasks."

at end check entry point , name of background task


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -