Search code examples
windowsuwptoastcortana

Opening the uri from background tasks in Universal windows apps


I know this sounds weird. Is there any way we can open a URI from background tasks in Windows 10 Apps?

I have 2 requirements,

  1. Talk to cortana and it will show you results based on the speech recognition, when user clicks on it, we cannot open the links in browser directly. Instead I am passing the Launch Context to the Foreground app and then using LauchUri I am opening the url in default browser.
  2. Send toast notifications from the App, when user clicks on it, I have requirement to open a url instead opening an app. So, did the same, by passing the launch context to foreground app and then opening the url.

Both scenarios, it just opening url in browser. Here user experience is very poor that user seeing the app open for each action and then opening browser. Please throw some ideas if any possibilities.

thanks in advance.


Solution

  • For your second requirement, you can make Toast Notifications launch a URL!

    If you're using the Notifications library (the NuGet package that we suggest you use), just set the Launch property to be a URL, and change the ActivationType to Protocol. You can also do this with raw XML, but that's error-prone.

    You can also make buttons on the toast launch a URL too, since they also support ActivationType of Protocol.

    Show(new ToastContent()
    {
        Visual = new ToastVisual()
        {
            BindingGeneric = new ToastBindingGeneric()
            {
                Children =
                {
                    new AdaptiveText() { Text = "See the news" },
                    new AdaptiveText() { Text = "Lots of great stories" }
                }
            }
        },
    
        Launch = "http://msn.com",
        ActivationType = ToastActivationType.Protocol
    });