私の Windows ストア アプリでは、ユーザーがファイルを開くことができるようにしています。ファイルがローカルに存在しない場合、アプリはファイルをダウンロードしてアプリのローカル フォルダーに保存し、以下のコードを使用して開こうとします。 これは断続的に機能し、それ以外の場合は呼び出しが false を返します。
var launcherOption = new LauncherOptions();
launcherOption.DesiredRemainingView = Windows.UI.ViewManagement.ViewSizePreference.Default;
launcherOption.DisplayApplicationPicker = userSettings.ShowApplicationPicker;
bool success;
// fileResponse.File is a StorageFile object
if (fileResponse.OpenAs == ContentOpenOption.LocalFile)
success = await Launcher.LaunchFileAsync(fileResponse.File, launcherOption);
else
success = await Launcher.LaunchUriAsync(fileResponse.WebUri, launcherOption);
私がチェックしたこと:
- ファイルは Windows によって制限されていません (例: exe、bin、bat ではなく、txt、jpg ファイルでテストしています)。
- この呼び出しが行われた時点で自分のアプリが表示されている
- 呼び出しは、以下のコードを使用して UI スレッドで行われます。
var launcherOption = new LauncherOptions();
launcherOption.DesiredRemainingView = Windows.UI.ViewManagement.ViewSizePreference.UseHalf;
launcherOption.DisplayApplicationPicker = userSettings.ShowApplicationPicker;
var dispatcherObject = CoreApplication.MainView.CoreWindow.Dispatcher;
if (dispatcherObject != null && dispatcherObject.HasThreadAccess == false)
{
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
Windows.UI.Core.CoreDispatcherPriority.Normal,
async () =>
{
if (fileResponse.OpenAs == ContentOpenOption.LocalFile)
success = await Launcher.LaunchFileAsync(fileResponse.File, launcherOption);
else
{
launcherOption.TreatAsUntrusted = true;
success = await Launcher.LaunchUriAsync(fileResponse.WebUri, launcherOption);
}
});
}
else
{
if (fileResponse.OpenAs == ContentOpenOption.LocalFile)
success = await Launcher.LaunchFileAsync(fileResponse.File, launcherOption);
else
{
launcherOption.TreatAsUntrusted = true;
success = await Launcher.LaunchUriAsync(fileResponse.WebUri, launcherOption);
}
}
if (!success)
{
content.IsContentUpdating = false;
content.ContentStatus = string.Empty;
logger.LogMessage(string.Format("Unable to open file. {0}",
content.Name), LoggingLevel.Error);
}
}
- ファイルのプロパティをチェックして、ファイルが Windows によってブロックされていないことを確認します。
ここで見逃している可能性のある他のアイデアはありますか?