我正在使用基于cordova的混合应用程序,目标是Windows 8.1平台。我正在使用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);},成功: function () {console.log(‘文件打开成功’);
} } );但它们都不起作用。
任何帮助都将不胜感激。
谢谢,希拉克。
发布于 2016-01-19 23:58:58
尽管没有很好的文档记录,但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名称空间。
https://stackoverflow.com/questions/32825442
复制相似问题