Search code examples
windows-8windows-runtimewindows-store-appswindows-store

Custom URL Scheme for Windows 8


Is there something similar for the Windows 8 platform to the custom url scheme found on the iOS platform?

I have found information on MSDN about an application URI scheme. This is not the answer.

In my iPad app, the user receives an email with a couple of long keys. The user clicks the url and my app opens to the right page with these values populated. Is there similar functionality available for Windows 8 that I have missed?


Solution

  • You're looking for protocol activation.

    You can add a supported protocol to Package.appxmanifest on the Declarations tab by adding a Protocol. This adds the following block to your Package.appxmanifest file:

    <Extensions>
      <Extension Category="windows.protocol">
        <Protocol Name="alrt" />
      </Extension>
    </Extensions>
    

    You need to handle protocol activation in App.xaml.cs by overriding OnActivated:

    protected override void OnActivated(IActivatedEventArgs args)
    {
        base.OnActivated(args);
    
        if (args.Kind == ActivationKind.Protocol)
        {
            var protocolArgs = args as ProtocolActivatedEventArgs;
    
            var rootFrame = new Frame();
            rootFrame.Navigate(typeof(MainPage), protocolArgs.Uri.AbsoluteUri);
            Window.Current.Content = rootFrame;
            Window.Current.Activate();
        }
    }
    

    Check this page for a more detailed explanation.