简体   繁体   中英

Open UWP application when an URL is clicked in the browser

I am developing a simple UWP page with a web view . I would like to know how can I open my application when an URL with https protocol is clicked in the browser. I have already tried this:

Package.appmanifest

 <uap:Extension Category="windows.protocol">
      <uap:Protocol Name="https">
        <uap:Logo>Assets\Logo.png</uap:Logo>
        <uap:DisplayName>test</uap:DisplayName>
      </uap:Protocol>
 </uap:Extension>

App.xaml.cs

protected override void OnActivated(IActivatedEventArgs args)
    {
        if (args.Kind == ActivationKind.Protocol)
        {
            // Retrieves the activation Uri.
            var protocolArgs = (ProtocolActivatedEventArgs)args;
            var uri = protocolArgs.Uri;

            var frame = Window.Current.Content as Frame;

            if (frame == null)
                frame = new Frame();

            // Navigates to MainPage, passing the Uri to it.
            frame.Navigate(typeof(MainPage), uri);
            Window.Current.Content = frame;

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

But when a click a link in the browser I dont have the option to opened it with my app. Has someone an idea??

您无法将应用程序绑定到内部协议(例如http / https )。

I think what you are doing is correct and it is possible to bind an app to the http protocol (according to this ).

But when a click a link in the browser I dont have the option to opened it with my app.

I think the app will be called when you are activating the protocol from another app except the browser. All browsers manage http: , https: and other similar protocols internally. Only few protocols like magnet: links or mailto: are passed on to the OS. So, try checking if your app works by clicking on a link from some other app. A quick example can be making an hyperlink in MS Word and trying to open it.

If you really want to open a link from the browser in your app, there are many other ways to do it, like implementing a share contract.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM