UWP 协议启动

  • 1.创建通过协议启动的项目 AppDemo
  • 2.在项目的Package.appxmanifest 文件里 Extensions 目录下
      <Extensions>
        <uap:Extension Category="windows.protocol">
          <uap:Protocol Name="uridemo">
            <uap:Logo>Assets\StoreLogo.png</uap:Logo>
            <uap:DisplayName>AppDemo</uap:DisplayName>
          </uap:Protocol>
        </uap:Extension>
      </Extensions>
View Code
  • 3.在App.xaml.cs里
        protected override void OnActivated(IActivatedEventArgs args)
        {
            base.OnActivated(args);
            // Window management
            Frame rootFrame = Window.Current.Content as Frame;
            if (rootFrame == null)
            {
                rootFrame = new Frame();
                Window.Current.Content = rootFrame;
            }
            switch (args.Kind)
            {
                case ActivationKind.VoiceCommand:
                    {
                        break;
                    }
                case ActivationKind.Protocol:
                    {
                        // Code specific to launch for results
                        var command = args as ProtocolActivatedEventArgs;

                        if (command.Uri.ToString().StartsWith("uridemo://"))
                        {
                            // Open the page that we created to handle activation for results.
                            rootFrame.Navigate(typeof(MainPage), command);

                        }
                        else
                        {
                            //.....
                        }
                        break;
                    }
            }

            // Ensure the current window is active.
            Window.Current.Activate();
        }
View Code
  • 4.在创建一个要启动的项目AppClient
        private async void button_Click(object sender, RoutedEventArgs e)
        {
            await Windows.System.Launcher.LaunchUriAsync(new Uri("uridemo://appdata"));
        }
View Code
  • 5.部署完成,启动AppClient

转载于:https://www.cnblogs.com/luquanmingren/p/7722827.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值