2016-01-12 39 views

回答

2

您可以launch the default app for a given URI簡單地與Launcher類,例如:

// The URI to launch 
var uri = new Uri(@"http://stackoverflow.com/q/34740877/50447"); 

// Launch the URI 
var success = await Windows.System.Launcher.LaunchUriAsync(uri); 

if (success) 
{ 
    // URI launched 
} 
else 
{ 
    // URI launch failed 
} 

這也支持自定義URI方案,那麼您可以使用URI像ms-drive-to:?cp=40.726966~-74.006076啓動驅動程序,以及獲取駕車前往那點在紐約。

同樣,你can register your own URI scheme,以便您可以啓動。所以,如果你不能找到通過URI激活處理翻譯的應用程序,你可以是自己可以採取的形式translate:{string}&from=en&to=es的URI和再有啓動的其他應用程序

1

我認爲這將樣本對你有幫助。
點擊這裏:How to launch an UWP app from another app

下面的代碼是核心:
在您的桌面應用。

Uri uri = new Uri("test-launchpage1://somepath"); 
//if you don't use this option, the system will show a confim box when you open new app 
var promptOptions = new Windows.System.LauncherOptions(); 
promptOptions.TreatAsUntrusted = false; 

bool isSuccess = await Windows.System.Launcher.LaunchUriAsync(uri, promptOptions); 

在你啓動應用程序:
在package.appxmainfest,你需要配置推出sechme,像這樣:

<Package> 
    <Applications> 
    <Application> 
     <Extensions> 
     <uap:Extension Category="windows.protocol"> 
      <uap:Protocol Name="test-launchpage1"> 
      <uap:DisplayName>LaunchPage1</uap:DisplayName> 
      </uap:Protocol> 
     </uap:Extension> 
     </Extensions> 
    </Application> 
    </Applications> 
</Package> 

而在你的應用程序推出的app.cs,你需要重寫事件處理器OnActivated,像這樣:

protected override void OnActivated(IActivatedEventArgs args) 
{ 
    if (args.Kind == ActivationKind.Protocol) 
    { 
     Frame rootFrame = Window.Current.Content as Frame; 

     if (rootFrame == null) 
     { 
      rootFrame = new Frame(); 
      Window.Current.Content = rootFrame; 
      rootFrame.NavigationFailed += OnNavigationFailed; 
     } 

     var protocolEventArgs = args as ProtocolActivatedEventArgs; 
     rootFrame.Navigate(typeof(MainPage), protocolEventArgs.Uri); 
     Window.Current.Activate(); 
    } 
} 
相關問題