LauncherOptions.FallbackUri 屬性

定義

取得或設定值,表示使用者應該在瀏覽器中取得的 URI,如果沒有應用程式來處理檔案類型或 URI。

public:
 property Uri ^ FallbackUri { Uri ^ get(); void set(Uri ^ value); };
Uri FallbackUri();

void FallbackUri(Uri value);
public System.Uri FallbackUri { get; set; }
var uri = launcherOptions.fallbackUri;
launcherOptions.fallbackUri = uri;
Public Property FallbackUri As Uri

屬性值

使用者應該在瀏覽器中前往的 URI。

範例

呼叫 Launcher.LaunchFileAsync (IStorageFile、LauncherOptions) | launchFileAsync (IStorageFile、LauncherOptions) 方法,並將 fallbackUri 設定為後援 URI。

// The URI to launch
string uriToLaunch = @ "contoso:somearguments";
var uri = new Uri(uriToLaunch);

// The fallback URI
string uriFallback = @ "http://www.contoso.com/somearguments";
var fallbackUri = new Uri(fallbackUri);

async void DefaultLaunch()
{
   // Set the fallback URI
   var options = new Windows.System.LauncherOptions();
   options.FallbackUri = fallbackUri;

   // Launch the URI with the fallback URI
   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"contoso:somearguments" };

// The fallback URI.
Windows::Foundation::Uri m_fallbackUri{ L"http://www.contoso.com/somearguments" };

Windows::Foundation::IAsyncAction MainPage::DefaultLaunch()
{
    // Set the fallback URI.
    Windows::System::LauncherOptions launcherOptions;
    launcherOptions.FallbackUri(m_fallbackUri);

    // 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("contoso:somearguments");

// The fallback URI
auto fallbackUri = ref new Windows::Foundation::Uri("http://www.contoso.com/somearguments");

void MainPage::DefaultLaunch()
{
   // Set the fallback URI
   auto launchOptions = ref new Windows::System::LauncherOptions();
   launchOptions->FallbackUri = fallbackUri;

   // Launch the URI with the fallback URI
   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("contoso:somearguments")

' The fallback URI
Dim fallbackUri As New Uri("http://www.contoso.com/somearguments")

async Sub DefaultLaunch()

   ' Set the fallback URI
   Dim options = Windows.System.LauncherOptions()
   options.FallbackUri = fallbackUri

   ' Launch the URI with the fallback URI
   Dim success = await Windows.System.Launcher.LaunchUriAsync(uri, options)

   If success Then
      ' URI launched
   Else
      ' URI launch failed
   End If

End Sub

備註

您只能使用 HTTP:// 或 HTTPs:// URI 來設定後援 URI 屬性。 如果已設定此屬性,而且未安裝任何應用程式來處理正在啟動的檔案或 URI,則會自動啟動使用者的預設瀏覽器,並流覽至指定的 URI。 使用者不會看到 [ 開啟時] 對話方塊,要求在此案例中選擇選項。 您應該只在將使用者導向至 Microsoft Store 時使用後援 URI,例如,只有未列在市集上的傳統型應用程式才支援檔案或 URI 的情況。 在所有 Microsoft Store 上有支援您啟動之檔案或 URI 的應用程式時,您應該使用 PreferredApplicationPackageFamilyNamePreferredApplicationDisplayName 來建議該應用程式給使用者。

您無法同時設定慣用的應用程式屬性和後援 URI,因為只能使用一個後援。 如果已設定這兩個後援,啟動器 API 將會失敗。

Windows 8.1僅限 Windows 8.1,此屬性也接受 Microsoft Store URI。 這些 URI 可用來做為 PreferredApplicationPackageFamilyNamePreferredApplicationDisplayName 屬性的替代方案,以將使用者傳送至市集中的特定應用程式,而不需彈出 [開啟方式 ] 對話方塊。 Windows Phone 8.1 或聚合式Windows 10應用程式不支援此功能,不建議使用此功能。

適用於

另請參閱