Jquery can';无法使用phonegap在android设备上运行getDirectory

Jquery can';无法使用phonegap在android设备上运行getDirectory,jquery,cordova,phonegap-build,Jquery,Cordova,Phonegap Build,我使用phonegap build为android编译我的应用程序。我需要创建一个永久文件夹来存储一些音频文件,但我无法让它工作。。。这是我的密码: 在config.xml中 <gap:plugin name="org.apache.cordova.file" version="0.2.4" /> 我没有解释你有什么线索吗?控制台没有给出任何信息。您的代码很好,但问题是您错过了错误回调。。。。因此,修改后的代码如下所示 document.addEventListener("dev

我使用phonegap build为android编译我的应用程序。我需要创建一个永久文件夹来存储一些音频文件,但我无法让它工作。。。这是我的密码:

在config.xml中

<gap:plugin name="org.apache.cordova.file" version="0.2.4" />

我没有解释你有什么线索吗?控制台没有给出任何信息。

您的代码很好,但问题是您错过了错误回调。。。。因此,修改后的代码如下所示

 document.addEventListener("deviceready", onDeviceReady, false);

// device APIs are available
//

function onDeviceReady() {
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
        fileSystem.root.getDirectory("mynewfolder", {create: true}, gotDir,fail);
        console.log(fileSystem.root);

}

function gotDir(dirEntry) {
        dirEntry.getFile("myfile.txt", {create: true, exclusive: true}, gotFile,fail);
}

function gotFile(fileEntry) {
        // Do something with fileEntry here
}  

function fail(error) {
    console.log(error.code);
}

您的代码很好,但问题是您错过了错误回调。。。。因此,修改后的代码如下所示

 document.addEventListener("deviceready", onDeviceReady, false);

// device APIs are available
//

function onDeviceReady() {
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
        fileSystem.root.getDirectory("mynewfolder", {create: true}, gotDir,fail);
        console.log(fileSystem.root);

}

function gotDir(dirEntry) {
        dirEntry.getFile("myfile.txt", {create: true, exclusive: true}, gotFile,fail);
}

function gotFile(fileEntry) {
        // Do something with fileEntry here
}  

function fail(error) {
    console.log(error.code);
}

谢谢你的帮助。事实上,使用fail函数它可以工作!执行fileSystem.root.getDirectory会导致调用失败,而不是gotDir调用。你知道为什么吗?console.log(filesystem.root)打印以下行:DirectoryEntry{isFile:false,isDirectory:true,name:=“”,fullPath:“/”,filesystem:filesystem,…}这段代码对我有用:但是我将cordova.file.applicationDirectory更改为cordova.file.externalrootdirectory谢谢你的帮助。事实上,使用fail函数它可以工作!执行fileSystem.root.getDirectory会导致调用失败,而不是gotDir调用。你知道为什么吗?console.log(filesystem.root)打印以下行:DirectoryEntry{isFile:false,isDirectory:true,name:=“”,fullPath:“/”,filesystem:filesystem,…}这段代码对我有用:但我将cordova.file.applicationDirectory更改为cordova.file.externalRootDirectory