Table of contents
Last Updated: 12/13/2016

You must apply to join the Cortana Developer Preview Program to create and use a Cortana skill.
Enroll in the Cortana developer preview today.

Deep link to a Universal Windows Platform app

A deep link is a URI that identifies specific content, functionality, or business logic provided by your app or web site. The URI typically includes data in the form of name/value pairs passed to your app as query string parameters.

Cortana skills require deep links. When you define a skill, you must create an associated deep link in the format supported by each targeted platform.

You create the deep link associated with a skill in the Cortana skill developer preview dashboard.

To enable deep links in a UWP app:

  1. In the package manifest of your app, add an extensibility point of type windows.protocol. This indicates that your app is registered as the default handler for the specified URI scheme.

    1. In Solution Explorer, right click the "Package.appxmanifest" file and select View Code.
    2. Find the Applications element, and then its Application child element.
    3. Add an Extensions child element to Application.
    4. Add a uap:Extension element to Extensions.
    5. Add a Category attribute to the uap:Extension element and set the value of the Category attribute to "windows.protocol".
    6. Add a uap:Protocol element to the uap:Extension element.
    7. Add a Name attribute to the uap:Protocol element and set the value of the Name attribute to a name of your app (for this example, "contosocafe").
    8. Add a uap:DisplayName element to the uap:Protocol element.
    9. Finally, set the content of the element to the display name of your app (for this example, "Contoso Cafe").
    <Applications>
    <Application>
    
     <Extensions>
       <uap:Extension Category="windows.protocol">
         <uap:Protocol Name="contosocafe">
           <uap:DisplayName>Contoso Cafe</uap:DisplayName>
         </uap:Protocol>
       </uap:Extension>
     </Extensions>
    
    <Application>
    <Applications>
    
  2. Override the OnActivated event handler in the App.Xaml.cs file of your app and process the URI activation. Here we open the main page of the Contoso Cafe app specified in the manifest.

Now add the following code to the OnActivated event handler in App.Xaml.cs.

public partial class App
{
  protected override void OnActivated(IActivatedEventArgs args) 
  {
    var rootFrame = CreateRootFrame();

    if (args.Kind == ActivationKind.Protocol)
    {
      var protocolArgs = args as ProtocolActivatedEventArgs;
      rootFrame.Navigate(typeof(MainPage), protocolArgs.Uri);
    }
    else
    {
      rootFrame.Navigate(typeof(MainPage));
    }

    // Ensure the current window is active
    Window.Current.Activate();
  }

  public Frame CreateRootFrame() 
  {
    Frame rootFrame = Window.Current.Content as Frame;

    // Do not repeat app initialization when the Window already has content,
    // just ensure that the window is active
    if (rootFrame == null)
    {
      // Create a Frame to act as the navigation context and navigate to the first page
      rootFrame = new Frame();

      rootFrame.NavigationFailed += OnNavigationFailed;

      // Place the frame in the current Window
      Window.Current.Content = rootFrame;
    }    
    return rootFrame;
  } 
}
© 2017 Microsoft