2014-01-24 36 views
2

我的应用程序我使用phonegap构建为android编译它。我需要创建一个持久的文件夹来存储一些音频文件,但我不能使它工作...这里是我的代码:config.xml中无法获取getDirectory在Android设备上使用phonegap

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

在我的index.html:

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); 
     console.log(fileSystem.root); 

} 

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

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

我没有解释你有一些线索吗?控制台什么都不给。

回答

3

嗯,你的代码是好的,但问题是你错过了错误回调....所以,你的修改后的代码看起来像

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); 
} 
+1

感谢您的帮助。事实上,它的失效功能是有效的! –

相关问题