Android PhoneGap在本机应用程序中打开文件。通过Build.phonegap.com构建
首先: 是的,在StackOverflow中有很多解决方案,但在我的例子中没有一个是有效的Android PhoneGap在本机应用程序中打开文件。通过Build.phonegap.com构建,android,pdf,cordova,smartgwt,phonegap-build,Android,Pdf,Cordova,Smartgwt,Phonegap Build,首先: 是的,在StackOverflow中有很多解决方案,但在我的例子中没有一个是有效的 我在SmartGWT.mobile中内置了应用程序 我将配置文件和所有需要的文件附加到此构建中,以便为PhoneGap做准备 应用程序是通过build.phonegap.com网站构建的 它在Android 4.1.1上运行得非常好 我想: 将文件下载到本地文件系统它是一个PDF文件-它工作正常使用: var fileTransfer = new FileTransfer(); fileTransfer.
var fileTransfer = new FileTransfer();
fileTransfer.download(.....
window.plugins.webintent.startActivity({
action: window.plugins.webintent.ACTION_VIEW,
type: "application/pdf",
url: encodeURI(theFile.toURL().substring(7))},
function() {},
function() {alert('Failed to open URL via Android Intent')}
);
但由于phonegap构建没有附加类文件,并且找不到WebIntent类,所以它无法工作
我在config.xml中声明此插件:
<gap:plugin name="com.borismus.webintent.WebIntent" />
你知道为什么它不起作用,或者我在做什么吗?
也许你们知道另一种打开文件的方法,就像在本机应用程序中一样,它应该很简单
我只想让我的应用程序下载并显示(在本机应用程序中)供用户使用的PDF。don的FileOpener版本已在我的应用程序cordova 3.0上运行
$("#page").on('pageshow', function(event, ui) {
if(event.handled !== true)
{
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
event.handled = true;
}
return false;
});
function fail() {
console.log("failed to get filesystem");
}
function gotFS(fileSystem) {
console.log("got filesystem");
// save the file system for later access
console.log(fileSystem.root.fullPath);
window.rootFS = fileSystem.root;
downloadImage(url, fileName);
}
function downloadImage(url, fileName){
var ft = new FileTransfer();
ft.download(
url,
window.rootFS.fullPath + "/" + fileName,
function(entry) {
console.log("download complete: " + entry.fullPath);
},
function(error) {
console.log("download error" + error.code);
}
);
}
phonegap local plugin add https://github.com/don/FileOpener
然后自动添加所有XML、插件等
在index.html上添加了fileopener.js
然后
<gap:plugin name="com.borismus.webintent.WebIntent" />
$("#page").on('pageshow', function(event, ui) {
if(event.handled !== true)
{
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
event.handled = true;
}
return false;
});
function fail() {
console.log("failed to get filesystem");
}
function gotFS(fileSystem) {
console.log("got filesystem");
// save the file system for later access
console.log(fileSystem.root.fullPath);
window.rootFS = fileSystem.root;
downloadImage(url, fileName);
}
function downloadImage(url, fileName){
var ft = new FileTransfer();
ft.download(
url,
window.rootFS.fullPath + "/" + fileName,
function(entry) {
console.log("download complete: " + entry.fullPath);
},
function(error) {
console.log("download error" + error.code);
}
);
}
phonegap local plugin add https://github.com/don/FileOpener
window.plugins.fileOpener.open( path );