UWP 协议启动
Posted androllen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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>
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(); }
4.在创建一个要启动的项目AppClient
private async void button_Click(object sender, RoutedEventArgs e) { await Windows.System.Launcher.LaunchUriAsync(new Uri("uridemo://appdata")); }
5.部署完成,启动AppClient
以上是关于UWP 协议启动的主要内容,如果未能解决你的问题,请参考以下文章