locked
Winphone 8.1 retreiving toast notifications when application not launched and toast content from launch via toast RRS feed

  • Question

  • Hi there, I wondered if anyone can point me in the right direction or confirm if this is actually possible.

    Looking to get the content of the toasts received whilst the application isn't running.

    Have used the example ( hh868212.aspx ) to get the launch= parameter via OnLaunched working with <toast launch="toast://my_arguments"> though can't see how to get the content of the toast message itself or any of the others messages.  Thinking of putting in the details I need into the launch= parameter which will work for one of them, however for the rest I can't see how to access them.

    Any suggestions would be greatly received, been google wacking and searching on this forum without luck, so any help or pointers will be gratefully received.

    Cheers

    p.s. sorry for the lack of proper linking or images first post here.

    Friday, November 20, 2015 4:09 PM

Answers

  • Hey TheMullet,

    Place all of the content your app needs to know about inside the launch attribute of the <toast> XML.

    For example, if you're writing a messaging app, you would have something like the following...

    <toast launch="conversationId=32">
     ...
    </toast>

    You can NOT retrieve the original toast notification XML. You can only retrieve the launch argument via your application's OnLaunched method via the Arguments property.

    If this doesn't work for you, please explain your exact scenario to us so we can help understand your requirements and propose a better solution for you.

    Thanks!
    Andrew

    • Proposed as answer by andrewbares7 Friday, November 20, 2015 5:53 PM
    • Marked as answer by themullet Monday, November 23, 2015 9:34 AM
    Friday, November 20, 2015 5:52 PM

All replies

  • Hey TheMullet,

    Place all of the content your app needs to know about inside the launch attribute of the <toast> XML.

    For example, if you're writing a messaging app, you would have something like the following...

    <toast launch="conversationId=32">
     ...
    </toast>

    You can NOT retrieve the original toast notification XML. You can only retrieve the launch argument via your application's OnLaunched method via the Arguments property.

    If this doesn't work for you, please explain your exact scenario to us so we can help understand your requirements and propose a better solution for you.

    Thanks!
    Andrew

    • Proposed as answer by andrewbares7 Friday, November 20, 2015 5:53 PM
    • Marked as answer by themullet Monday, November 23, 2015 9:34 AM
    Friday, November 20, 2015 5:52 PM
  • Hi Andrew, thanks for the help.

    Will place all the needed bits inside the launch attribute.

    Just checking is there no way to retrieve the other toasts / push notifications? As what I think will happen is; "I send 3 pushes and the application only sees the launch attribute from the one the user clicked on" and there's no way of knowing about the other pushes?

    Thanks again for the reply.

    Monday, November 23, 2015 9:40 AM
  • You can use ToastNotificationHistory.GetHistory() to obtain all the current toast notifications that are in action center (if you're calling that after being clicked, it won't include your toast that was just clicked on, since clicking on a notification removes it from action center, but you can "know about the other toasts" by using this).

    foreach (ToastNotification n in ToastNotificationManager.History.GetHistory())
    {
    }

    Also, make sure to use the History API to clear relevant notifications! For example, when the user clicks on a toast for a conversation, make sure to clear all the toasts for that conversation! The easiest way to do that is to use the Group property on ToastNotification. Assign the Group as the conversation ID, and then you can clear all notifications that have the Group of your conversation ID the user opened.

    Monday, November 23, 2015 8:32 PM
  • Thank you very much, though in Windows Phone 8.1 doesn't seems to have a GetHistory() method with the Windows.UI.Notifications.ToastNotificationManager.History call.

    • Edited by themullet Tuesday, November 24, 2015 10:38 AM
    Tuesday, November 24, 2015 10:35 AM
  • Ah sorry, I suppose the History API's didn't exist back in WP 8.1. In that case, there's nothing else you can do and you'd have to upgrade to UWP. Or just rely on receiving the launch args from the toast that was clicked - that's been sufficient for every app we know of. I'd be curious to know how exactly you were planning on utilizing the other toasts (we appreciate devs thinking of new innovative things! But we've simply never designed the platform with that scenario in mind, since it's never been asked for.)
    Thursday, November 26, 2015 6:28 AM
  • Just as a heads up, ended up moving to raw notifications with a background process which could handle history.
    Tuesday, February 23, 2016 10:21 AM