简体   繁体   English

科尔多瓦在Windows 8.1平台上打开本地文件

[英]cordova open local file on windows 8.1 platform

I am working with cordova based hybrid application targeted to Windows 8.1 platform. 我正在使用针对Windows 8.1平台的基于cordova的混合应用程序。 I am using Visual Studio 2013 Update 4 IDE for debugging and testing. 我正在使用Visual Studio 2013 Update 4 IDE进行调试和测试。 I am trying to open an image saved locally on device say "C:\\image.jpg" 我正在尝试打开本地保存在设备“ C:\\ image.jpg”上的图像

I tried multiple options like: 我尝试了多个选项,例如:

Use of window.open with file protocol as window.open("file:///C:/image.jpg"); 使用window.open,并将文件协议用作window.open(“ file:/// C:/image.jpg”);

Also tried fileopener2 plugin as 还尝试了fileopener2插件作为

cordova.plugins.fileOpener2.open( 'C://image.jpg', 'application/jpg', { error : function(e) { console.log('Error status: ' + e.status + ' - Error message: ' + e.message); }, success : function () { console.log('file opened successfully'); cordova.plugins.fileOpener2.open('C://image.jpg','application / jpg',{错误:函数(e){console.log('错误状态:'+ e.status +'-错误消息:'+ e.message);},成功:function(){console.log('文件成功打开');
} } ); }});

But none of them works. 但是它们都不起作用。

Any help will be much appreciated. 任何帮助都感激不尽。

Thanks, Chirag. 谢谢,Chirag。

Although it's not very well documented, cordova childBrowser doesn't support opening non-HTML files. 尽管没有很好的文档记录,cordova childBrowser不支持打开非HTML文件。 This is due to the underlying child Browser implementation provided by Microsoft. 这是由于Microsoft提供的基础子浏览器实现。

Either let the user pick an external app to open the file as described in 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");
                            }
                        });
                  });

or take a look at the Windows.Data.Pdf namespace if you'd like to try rolling your own in-app solution. 或查看Windows.Data.Pdf命名空间(如果您想尝试滚动自己的应用程序内解决方案)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM