【发布时间】:2014-04-10 09:22:17
【问题描述】:
我正在使用 Phonegap (Apache Cordova) 版本开发移动应用程序。适用于 Android 平台和 iOS 的 3.3.0。
这个应用程序应该能够在移动设备中创建一个目录,并访问该目录以保存我从外部 url 下载的一些文件。
应用程序现在可以正确创建目录,并且可以访问它来保存文件。 问题是我想让它成为一个“受保护”的目录:directort 应该只在我的应用程序中按一个按钮打开,但不能从其他任何地方访问。
我怎样才能意识到这一点?
这是我的代码,用于创建目录。
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);
}
function onFileSystemSuccess(fileSystem) {
console.log(fileSystem.name);
console.log(fileSystem.root.name);
var directoryEntry = fileSystem.root;
directoryEntry.getDirectory("myDir", {create: true, exclusive: false}, onDirectorySuccess, onDirectoryFail);
}
function onDirectorySuccess(parent) {
console.log(parent);
//parent.fullPath = path to dir in smartphone
window.localStorage.setItem("directory_path",parent.fullPath);
}
function onDirectoryFail(error) {
alert("Unable to create new directory: " + error.code);
}
function fail(evt) {
console.log(evt.target.error.code);
}
【问题讨论】: