簡體   English   中英

科爾多瓦在Windows 8.1平台上打開本地文件

[英]cordova open local file on windows 8.1 platform

我正在使用針對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','application / jpg',{錯誤:函數(e){console.log('錯誤狀態:'+ e.status +'-錯誤消息:'+ e.message);},成功:function(){console.log('文件成功打開');
}});

但是它們都不起作用。

任何幫助都感激不盡。

謝謝,Chirag。

盡管沒有很好的文檔記錄,cordova childBrowser不支持打開非HTML文件。 這是由於Microsoft提供的基礎子瀏覽器實現。

讓用戶選擇一個外部應用程序以打開此問題中所述的文件

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命名空間(如果您想嘗試滾動自己的應用程序內解決方案)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM