Launcher.LaunchUriAsync 方法   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
| LaunchUriAsync(Uri, LauncherOptions, ValueSet) | 使用指定的选项和输入数据启动与指定 URI 的 URI 方案名称关联的默认应用。 | 
| LaunchUriAsync(Uri, LauncherOptions) | 使用指定的选项启动与 URI 方案名称关联的默认应用或由 ContentType 指定的应用。 | 
| LaunchUriAsync(Uri) | 启动与指定 URI 的 URI 方案名称关联的默认应用。 | 
LaunchUriAsync(Uri, LauncherOptions, ValueSet)
使用指定的选项和输入数据启动与指定 URI 的 URI 方案名称关联的默认应用。
public:
 static IAsyncOperation<bool> ^ LaunchUriAsync(Uri ^ uri, LauncherOptions ^ options, ValueSet ^ inputData);/// [Windows.Foundation.Metadata.Overload("LaunchUriWithDataAsync")]
 static IAsyncOperation<bool> LaunchUriAsync(Uri const& uri, LauncherOptions const& options, ValueSet const& inputData);[Windows.Foundation.Metadata.Overload("LaunchUriWithDataAsync")]
public static IAsyncOperation<bool> LaunchUriAsync(System.Uri uri, LauncherOptions options, ValueSet inputData);function launchUriAsync(uri, options, inputData)Public Shared Function LaunchUriAsync (uri As Uri, options As LauncherOptions, inputData As ValueSet) As IAsyncOperation(Of Boolean)参数
- options
- LauncherOptions
应用的启动选项。
重要
选项 参数的 TargetApplicationPackageFamilyName 属性(有时为可选)对于 LaunchUriAsync 方法的此重载是必需的。
返回
如果启动 URI 方案的默认应用,则返回 true;否则,false。
- 属性
注解
除非从 Windows 桌面应用程序调用此 API,否则必须在 ASTA 线程(也称为 UI 线程)中调用此 API。
也可以从 Windows 桌面应用程序调用此 API。
此 API 为方案启动默认应用,无论是通用 Windows 平台(UWP)应用还是 Windows 桌面应用程序。
另请参阅
适用于
LaunchUriAsync(Uri, LauncherOptions)
使用指定的选项启动与 URI 方案名称关联的默认应用或由 ContentType 指定的应用。
public:
 static IAsyncOperation<bool> ^ LaunchUriAsync(Uri ^ uri, LauncherOptions ^ options);/// [Windows.Foundation.Metadata.Overload("LaunchUriWithOptionsAsync")]
 static IAsyncOperation<bool> LaunchUriAsync(Uri const& uri, LauncherOptions const& options);[Windows.Foundation.Metadata.Overload("LaunchUriWithOptionsAsync")]
public static IAsyncOperation<bool> LaunchUriAsync(System.Uri uri, LauncherOptions options);function launchUriAsync(uri, options)Public Shared Function LaunchUriAsync (uri As Uri, options As LauncherOptions) As IAsyncOperation(Of Boolean)参数
- options
- LauncherOptions
应用的启动选项。
返回
如果启动 URI 方案的默认应用,则返回 true;否则,false。
- 属性
示例
此示例使用 [LaunchUriAsync(Uri, LauncherOptions) 启动带有警告的 URI。 TreatAsUntrusted 属性指示系统应显示警告。
// The URI to launch
string uriToLaunch = @"http://www.bing.com";
var uri = new Uri(uriToLaunch);
async void DefaultLaunch()
{
   // Set the option to show a warning
   var options = new Windows.System.LauncherOptions();
   options.TreatAsUntrusted = true;
   // Launch the URI with a warning prompt
   var success = await Windows.System.Launcher.LaunchUriAsync(uri, options);
   if (success)
   {
      // URI launched
   }
   else
   {
      // URI launch failed
   }
}
// The URI to launch.
Windows::Foundation::Uri m_uri{ L"http://www.bing.com" };
Windows::Foundation::IAsyncAction MainPage::DefaultLaunch()
{
    // Set the option to show a warning
    Windows::System::LauncherOptions launcherOptions;
    launcherOptions.TreatAsUntrusted(true);
    // Launch the URI.
    if (co_await Windows::System::Launcher::LaunchUriAsync(m_uri, launcherOptions))
    {
        // URI launched.
    }
    else
    {
        // URI launch failed.
    }
}
// The URI to launch
auto uri = ref new Windows::Foundation::Uri("http://www.bing.com");
void MainPage::DefaultLaunch()
{
   // Set the option to show a warning
   auto launchOptions = ref new Windows::System::LauncherOptions();
   launchOptions->TreatAsUntrusted = true;
   // Launch the URI with a warning prompt
   concurrency::task<bool> launchUriOperation(Windows::System::Launcher::LaunchUriAsync(uri, launchOptions));
   launchUriOperation.then([](bool success)
   {
      if (success)
      {
         // URI launched
      }
      else
      {
         // URI launch failed
      }
   });
}
' The URI to launch
Dim uri As New Uri("http://www.bing.com")
async Sub DefaultLaunch()
   ' Set the option to show a warning
   Dim options = Windows.System.LauncherOptions()
   options.TreatAsUntrusted = True
   ' Launch the URI with a warning prompt
   Dim success = await Windows.System.Launcher.LaunchUriAsync(uri, options)
   If success Then
      ' URI launched
   Else
      ' URI launch failed
   End If
End Sub
注解
除非从 Windows 桌面应用程序调用此 API,否则必须在 ASTA 线程(也称为 UI 线程)中调用此 API。
也可以从 Windows 桌面应用程序调用此 API。
此 API 为方案启动默认应用,无论是通用 Windows 平台(UWP)应用还是 Windows 桌面应用程序。
调用此 API 时,调用应用必须对用户可见。
除非从 Windows 桌面应用程序调用此 API,否则必须在 ASTA 线程(也称为 UI 线程)内调用此 API。
必须在清单中指定 privateNetworkClientServer 功能才能启动 Intranet URI,例如指向网络位置的 file:/// URI。
不能使用此方法在本地区域中启动 URI。 例如,应用无法使用 file:/// 协议访问本地计算机上的文件。 相反,必须使用 存储 API 来访问文件。
内容类型用于从默认应用选择的扩展中计算文件扩展名。 例如,内容类型值“”application/vnd.ms-word.document.12“映射到”.docx“,然后启动”.docx“的默认应用程序。 例如:
// this specifies the file type, which is used to bind to Word. 
launcherOptions.ContentType = "application/vnd.ms-word.document.12"; 
// and then this launches the file using the application
Launcher.LaunchUriAsync("http://www.cloud.com/file.docx", options);
如果出于上述任何原因启动失败,API 将成功并从其异步操作返回 FALSE。
若要让用户选择应用而不是启动默认应用,请设置 LauncherOptions.DisplayApplicationPicker 属性。
若要显示 URI 可能不安全的警告,请设置 LauncherOptions.TreatAsUntrusted 属性。
URI 将传递给关联的应用。 如果关联的应用是桌面应用,则会使用 shell 执行机制传递 URI。
另请参阅
适用于
LaunchUriAsync(Uri)
启动与指定 URI 的 URI 方案名称关联的默认应用。
public:
 static IAsyncOperation<bool> ^ LaunchUriAsync(Uri ^ uri);/// [Windows.Foundation.Metadata.Overload("LaunchUriAsync")]
 static IAsyncOperation<bool> LaunchUriAsync(Uri const& uri);[Windows.Foundation.Metadata.Overload("LaunchUriAsync")]
public static IAsyncOperation<bool> LaunchUriAsync(System.Uri uri);function launchUriAsync(uri)Public Shared Function LaunchUriAsync (uri As Uri) As IAsyncOperation(Of Boolean)参数
返回
如果启动 URI 方案的默认应用,则返回 true;否则,false。
- 属性
示例
此示例使用 LaunchUriAsync(Uri) 启动 URI。
// The URI to launch
string uriToLaunch = @"http://www.bing.com";
// Create a Uri object from a URI string 
var uri = new Uri(uriToLaunch);
// Launch the URI
async void DefaultLaunch()
{
   // Launch the URI
   var success = await Windows.System.Launcher.LaunchUriAsync(uri);
   if (success)
   {
      // URI launched
   }
   else
   {
      // URI launch failed
   }
}
// The URI to launch.
Windows::Foundation::Uri m_uri{ L"http://www.bing.com" };
...
Windows::Foundation::IAsyncAction MainPage::DefaultLaunch()
{
    // Launch the URI.
    if (co_await Windows::System::Launcher::LaunchUriAsync(m_uri))
    {
        // URI launched.
    }
    else
    {
        // URI launch failed.
    }
}
// The URI to launch
auto uri = ref new Windows::Foundation::Uri("http://www.bing.com");
void MainPage::DefaultLaunch()
{
   // Launch the URI
   concurrency::task<bool> launchUriOperation(Windows::System::Launcher::LaunchUriAsync(uri));
   launchUriOperation.then([](bool success)
   {
      if (success)
      {
         // URI launched
      }
      else
      {
         // URI launch failed
      }
   });
}
' The URI to launch
Dim uri As New Uri("http://www.bing.com")
async Sub DefaultLaunch()
   ' Launch the URI
   Dim success = await Windows.System.Launcher.LaunchUriAsync(uri)
   If success Then
      ' URI launched
   Else
      ' URI launch failed
   End If
End Sub
注解
除非从 Windows 桌面应用程序调用此 API,否则必须在 ASTA 线程(也称为 UI 线程)中调用此 API。
也可以从 Windows 桌面应用程序调用此 API。
此 API 为方案启动默认应用,无论是通用 Windows 平台(UWP)应用还是 Windows 桌面应用程序。
调用 API 时,调用应用必须对用户可见。
必须在清单中指定 privateNetworkClientServer 功能才能启动 Intranet URI,例如指向网络位置的 file:/// URI。
不能使用此方法在本地区域中启动 URI。 例如,应用无法使用 file:/// 协议访问本地计算机上的文件。 相反,必须使用 存储 API 来访问文件。
如果出于上述任何原因启动失败,API 将成功并从其异步操作返回 FALSE。
若要让用户选择应用而不是启动默认应用,请设置 LauncherOptions.DisplayApplicationPicker 属性。
若要显示 URI 可能不安全的警告,请设置 LauncherOptions.TreatAsUntrusted 属性。
URI 将传递给关联的应用。 如果关联的应用是桌面应用,则会使用 shell 执行机制传递 URI。
另请参阅
- LaunchUriAsync(Uri, LauncherOptions)
- LaunchUriAsync(Uri, LauncherOptions, ValueSet)
- 关联启动示例
- 文件类型和 URI 指南
- 启动 URI 的默认应用