Launcher.LaunchUriAsync 方法

定義

多載

LaunchUriAsync(Uri, LauncherOptions, ValueSet)

使用指定的選項和輸入資料,啟動與指定 URI 配置名稱相關聯的預設應用程式。

LaunchUriAsync(Uri, LauncherOptions)

使用指定的選項,啟動與 URI 配置名稱相關聯的預設應用程式,或由 ContentType 為指定 URI 所指定的應用程式。

LaunchUriAsync(Uri)

啟動與指定 URI 之 URI 配置名稱相關聯的預設應用程式。

LaunchUriAsync(Uri, LauncherOptions, ValueSet)

使用指定的選項和輸入資料,啟動與指定 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 執行緒內呼叫此 API, (也稱為 UI 執行緒) 。

您也可以從 Windows 傳統型應用程式呼叫此 API。

此 API 會啟動配置的預設應用程式,無論是通用 Windows 平臺 (UWP) 應用程式或 Windows 傳統型應用程式。

另請參閱

適用於

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 執行緒內呼叫此 API, (也稱為 UI 執行緒) 。

您也可以從 Windows 傳統型應用程式呼叫此 API。

此 API 會啟動配置的預設應用程式,無論是通用 Windows 平臺 (UWP) 應用程式或 Windows 傳統型應用程式。

叫用此 API 時,使用者必須可以看到呼叫的應用程式。

除非您從 Windows 傳統型應用程式呼叫此 API,否則必須在 ASTA 執行緒內呼叫此 API, (也稱為 UI 執行緒) 。

您必須在資訊清單中指定 privateNetworkClientServer 功能,才能啟動內部網路 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 會傳遞至相關聯的應用程式。 如果相關聯的應用程式是傳統型應用程式,則會使用殼層執行機制傳遞 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 執行緒內呼叫此 API, (也稱為 UI 執行緒) 。

您也可以從 Windows 傳統型應用程式呼叫此 API。

此 API 會啟動配置的預設應用程式,無論是通用 Windows 平臺 (UWP) 應用程式或 Windows 傳統型應用程式。

叫用 API 時,使用者必須可以看到呼叫的應用程式。

您必須在資訊清單中指定 privateNetworkClientServer 功能,才能啟動內部網路 URI,例如指向網路位置的 file:/// URI。

您無法使用此方法在本機區域中啟動 URI。 例如,應用程式無法使用 file:/// 通訊協定來存取本機電腦上的檔案。 相反地,您必須使用 儲存體 API 來存取檔案。

當啟動因上述任何原因而失敗時,API 將會成功,並從其非同步作業傳回 FALSE。

若要讓使用者選擇應用程式,而不是啟動預設應用程式,請設定 LauncherOptions.DisplayApplicationPicker 屬性。

若要顯示 URI 可能不安全的警告,請設定 LauncherOptions.TreatAsUntrusted 屬性。

URI 會傳遞至相關聯的應用程式。 如果相關聯的應用程式是傳統型應用程式,則會使用殼層執行機制傳遞 URI。

另請參閱

適用於