【问题标题】:cordova open local file on windows 8.1 platformcordova 在 windows 8.1 平台上打开本地文件
【发布时间】:2015-09-28 14:24:29
【问题描述】:

我正在使用针对 Windows 8.1 平台的基于 Cordova 的混合应用程序。我正在使用 Visual Studio 2013 Update 4 IDE 进行调试和测试。我正在尝试打开设备上本地保存的图像说“C:\image.jpg”

我尝试了多种选择,例如:

window.open 与文件协议的使用为 window.open("file:///C:/image.jpg");

也试过fileopener2插件

cordova.plugins.fileOpener2.open( 'C://image.jpg', '应用程序/jpg', { 错误:函数(e){ console.log('错误状态:' + e.status + ' - 错误信息:' + e.message); }, 成功:函数(){ console.log('文件打开成功');
} } );

但它们都不起作用。

任何帮助将不胜感激。

谢谢, 奇拉格。

【问题讨论】:

    标签: cordova windows-8.1 window.open local-files


    【解决方案1】:

    虽然没有很好的文档记录,但 cordova childBrowser 不支持打开非 HTML 文件。这是由于 Microsoft 提供的底层子浏览器实现。

    this question中所述,让用户选择一个外部应用程序来打开文件

    var applicationData = Windows.Storage.ApplicationData.current;
                    var localFolder = applicationData.localFolder;
                    console.log(localFolder);
    
                    var imageFile = "image.png";
    
                    // Get the image file from the package's image directory
                    localFolder.getFileAsync(imageFile).then(
                      function (file) {
                          console.log("1");
                          // Set the show picker option
                          var options = new Windows.System.LauncherOptions();
                          options.displayApplicationPicker = true;
    
                          // Launch the retrieved file using the selected app
                          Windows.System.Launcher.launchFileAsync(file, options).then(
                            function (success) {
                                if (success) {
                                    // File launched
                                    console.log("2");
                                } else {
                                    // File launch failed
                                    console.log("3");
                                }
                            });
                      });
    

    如果您想尝试推出自己的应用内解决方案,请查看 Windows.Data.Pdf 命名空间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多