Launcher.LaunchUriAsync 方法

定义

重载

LaunchUriAsync(Uri, LauncherOptions, ValueSet)

使用指定的选项和输入数据启动与指定 URI 的 URI 方案名称关联的默认应用。

LaunchUriAsync(Uri, LauncherOptions)

使用指定的选项启动与 URI 方案名称关联的默认应用,或者由 ContentType 为指定 URI 指定的应用。

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)

参数

uri
Uri Uri

URI。

options
LauncherOptions

应用的启动选项。

inputData
ValueSet

应用的输入数据。

重要

可以传输的数据量不能超过 100 KB。

返回

如果 URI 方案的默认应用已启动,则返回 true ;否则 为 false

属性

注解

除非从 Windows 桌面应用程序调用此 API,否则必须从 ASTA 线程 (也称为 UI 线程) 调用此 API。

也可以从 Windows 桌面应用程序调用此 API。

无论是通用 Windows 平台 (UWP) 应用还是 Windows 桌面应用程序,此 API 都会启动方案的默认应用。

另请参阅

适用于

LaunchUriAsync(Uri, LauncherOptions)

使用指定的选项启动与 URI 方案名称关联的默认应用,或者由 ContentType 为指定 URI 指定的应用。

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)

参数

uri
Uri Uri

URI。

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。

无论是通用 Windows 平台 (UWP) 应用还是 Windows 桌面应用程序,此 API 都会启动方案的默认应用。

调用此 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
Uri Uri

URI。

返回

如果 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。

无论是通用 Windows 平台 (UWP) 应用还是 Windows 桌面应用程序,此 API 都会启动方案的默认应用。

调用 API 时,调用应用必须对用户可见。

必须在清单中指定 privateNetworkClientServer 功能才能启动 Intranet URI,例如指向网络位置的 file:/// URI。

不能使用此方法在本地区域中启动 URI。 例如,应用不能使用 file:/// 协议访问本地计算机上的文件。 相反,必须使用 存储 API 来访问文件。

当启动因上述任何原因而失败时,API 将成功,并从其异步操作返回 FALSE。

若要使用户能够选择应用而不是启动默认应用,请设置 LauncherOptions.DisplayApplicationPicker 属性。

若要显示 URI 可能不安全的警告,请设置 LauncherOptions.TreatAsUntrusted 属性。

URI 将传递到关联的应用。 如果关联的应用是桌面应用,则使用 shell 执行机制传递 URI。

另请参阅

适用于