LauncherOptions.PreferredApplicationDisplayName プロパティ

定義

ファイルの種類または URI を処理するアプリが存在しない場合にユーザーがインストールするストア内のアプリの表示名を表す値を取得または設定します。

public:
 property Platform::String ^ PreferredApplicationDisplayName { Platform::String ^ get(); void set(Platform::String ^ value); };
winrt::hstring PreferredApplicationDisplayName();

void PreferredApplicationDisplayName(winrt::hstring value);
public string PreferredApplicationDisplayName { get; set; }
var string = launcherOptions.preferredApplicationDisplayName;
launcherOptions.preferredApplicationDisplayName = string;
Public Property PreferredApplicationDisplayName As String

プロパティ値

String

Platform::String

winrt::hstring

アプリの表示名です。

Launcher.LaunchFileAsync(IStorageFile, LauncherOptions) | launchFileAsync(IStorageFile, LauncherOptions) メソッドを呼び出し、preferredApplicationDisplayName を Windows ストア内のアプリの表示名に設定し、preferredApplicationPackageFamilyName を Windows ストア内のアプリのパッケージ ファミリ名に設定します。

async void DefaultLaunch()
{
   // Path to the file in the app package to launch
   string imageFile = @"images\test.png";

   // Get the image file from the package's image directory
   var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);

   if (file != null)
   {
      // Set the recommended app
      var options = new Windows.System.LauncherOptions();
      options.PreferredApplicationPackageFamilyName = "Contoso.FileApp_8wknc82po1e";
      options.PreferredApplicationDisplayName = "Contoso File App";


      // Launch the retrieved file pass in the recommended app 
      // in case the user has no apps installed to handle the file
      bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
      if (success)
      {
         // File launched
      }
      else
      {
         // File launch failed
      }
   }
   else
   {
      // Could not find file
   }
}
Windows::Foundation::IAsyncAction MainPage::DefaultLaunch()
{
    // Get the app's installation folder.
    Windows::Storage::StorageFolder installFolder{ Windows::ApplicationModel::Package::Current().InstalledLocation() };

    Windows::Storage::StorageFile file{ co_await installFolder.GetFileAsync(L"Assets\\LockScreenLogo.scale-200.png") };

    if (file)
    {
        // Set the recommended app.
        Windows::System::LauncherOptions launcherOptions;
        launcherOptions.PreferredApplicationPackageFamilyName(L"Contoso.FileApp_8wknc82po1e");
        launcherOptions.PreferredApplicationDisplayName(L"Contoso File App");

        // Launch the retrieved file.
        bool success{ co_await Windows::System::Launcher::LaunchFileAsync(file, launcherOptions) };
        if (success)
        {
            // File launched.
        }
        else
        {
            // File launch failed.
        }
    }
    else
    {
        // Couldn't find file.
    }
}
void MainPage::DefaultLaunch()
{
   auto installFolder = Windows::ApplicationModel::Package::Current->InstalledLocation;

   concurrency::task<Windows::Storage::StorageFile^> getFileOperation(installFolder->GetFileAsync("images\\test.png"));
   getFileOperation.then([](Windows::Storage::StorageFile^ file)
   {
      if (file != nullptr)
      {
         // Set the recommended app
         auto launchOptions = ref new Windows::System::LauncherOptions();
         launchOptions->PreferredApplicationPackageFamilyName = "Contoso.FileApp_8wknc82po1e";
         launchOptions->PreferredApplicationDisplayName = "Contoso File App";

         // Launch the retrieved file pass in the recommended app 
         // in case the user has no apps installed to handle the file
         concurrency::task<bool> launchFileOperation(Windows::System::Launcher::LaunchFileAsync(file, launchOptions));
         launchFileOperation.then([](bool success)
         {
            if (success)
            {
               // File launched
            }
            else
            {
               // File launch failed
            }
         });
      }
      else
      {
         // Could not find file
      }
   });
}
async Sub DefaultLaunch()

   ' Path to the file in the app package to launch
   Dim imageFile = "images\test.png"

   ' Get the image file from the package's image directory
   Dim file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile)

   If file IsNot Nothing Then
      ' Set the recommended app
      Dim options = Windows.System.LauncherOptions()
      options.PreferredApplicationPackageFamilyName = "Contoso.FileApp_8wknc82po1e";
      options.PreferredApplicationDisplayName = "Contoso File App";

      ' Launch the retrieved file pass in the recommended app 
      ' in case the user has no apps installed to handle the file
      Dim success = await Windows.System.Launcher.LaunchFileAsync(file)

      If success Then
         ' File launched
      Else
         ' File launch failed
      End If
   Else
      ' Could not find file
   End If
End Sub

注釈

場合によっては、起動中のファイルを処理するためのアプリがインストールされていないこともあります。 既定では、Windows はストア上の適切なアプリを検索するリンクを表示して、これらのケースに対処します。 LauncherOptions.PreferredApplicationDisplayName をLauncherOptions.preferredApplicationPackageFamilyName と組み合わせて使用して、ファイルを処理するために取得できる Windows ストア内のアプリをユーザーに提供します。 使用する表示名は、Windows ストア内のアプリの表示名に対応している必要があります。

アプリを推奨するには、これらの優先アプリケーション プロパティの両方を設定する必要があります。 どちらか一方のみを設定した場合は、エラーになります。

Note

1 つのフォールバックしか使用できないため、優先アプリケーションのプロパティとフォールバック URI を同時に設定することはできません。 両方のフォールバックが設定されている場合、Launcher API は失敗します。

重要

このプロパティは、デスクトップ デバイスでのみ実装されます。

適用対象

こちらもご覧ください