【问题标题】:DisplayApplicationPicker not showing open with promptDisplayApplicationPicker 未显示打开提示
【发布时间】:2018-05-07 05:36:28
【问题描述】:

我正在创建一个 Xamarin Forms 应用程序(目前只有 UWP),我想在其中打开本地存储中的 PDF 文件。在 UWP 项目中,我收到来自 Xamarin 便携式项目的文件路径。我使用以下函数打开 Open With Prompt。

 public void OpenFileWith(string path)
 {
     Task.Run(async () =>
     {
         var file = await StorageFile.GetFileFromPathAsync(path);

         if (file != null)
         {
             var options = new LauncherOptions();
             options.DisplayApplicationPicker = true;
             var success = await Launcher.LaunchFileAsync(file, options);

             if (success)
             {
                 //File Launched
             }
             else
             {
                 //File Launch Failed
             }
         }
      });
  }

我认为我根据Documentation 所做的一切都是正确的。当我不添加 LauncherOptions 时,文件会在默认选择的应用程序中正确打开。

我有什么遗漏的吗?也许是权限?我知道文档中有一条注释“此属性仅在桌面设备上实现。”。我正在桌面上进行测试(通过 VMWare 的 Windows 10)

【问题讨论】:

    标签: c# windows xamarin.forms uwp xamarin.uwp


    【解决方案1】:

    这应该可行:

        public async Task OpenFileWithAsync(string path)
        {
            var file = await StorageFile.GetFileFromPathAsync(path);
    
            if (file != null)
            {
                var options = new LauncherOptions();
                options.DisplayApplicationPicker = true;
                var success = await Launcher.LaunchFileAsync(file, options);
    
                if (success)
                {
                    //File Launched
                }
                else
                {
                    //File Launch Failed
                }
            }
        }
    

    呼叫:

        await OpenFileWithAsync(...);
    

    【讨论】:

    • 试过你的答案没有成功。难道是文件在本地文件夹中?
    • @DevelopingBeaver,它可以。 UWP 应用程序对文件系统的访问受到严格监管(请参阅文档的File access permissions 部分)。只是为了测试,将您的 PDF 文件放置在您的应用程序可以毫无问题地访问它的地方(例如,在 Pictures 文件夹中并将 PicturesLibrary 功能添加到您的应用程序的清单中)。
    • 我已将下载和存储文档的过程从 Xamarin 便携式项目转移到 UWP 项目。此 Dows 正确打开并提示打开。
    猜你喜欢
    • 1970-01-01
    • 2014-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-21
    相关资源
    最近更新 更多