[英]How can I read/write files in Android/iOs devices subdirectories using Cordova File Plugin?
I'm trying this code:我正在尝试这个代码:
function onDeviceReady() {
requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
alert(fileSystem.root.toURL());
fileSystem.root.getDirectory('myDir', { create: true }, function (myDirEntry) {
alert(myDirEntry.toURL());
myDirEntry.getDirectory('mySubDir', { create: true }, function (mySubDirEntry) {
alert(mySubDirEntry.toURL());
alert('/myDir/mySubDir creation is done');
}, getDirectoryError);
}, getDirectoryError);
}, requestFileSystemError);
As a result of executing it on a Samsung SM-G318ML, Kernel version 3.10.17-983426, I got alerts showing the following messages:由于在三星 SM-G318ML 内核版本 3.10.17-983426 上执行它,我收到了显示以下消息的警报:
file:data/data/com.mydomain.myapp/files/files/
file:data/data/com.mydomain.myapp/files/files/myDir
file:data/data/com.mydomain.myapp/files/files/myDir/mySubDir
/myDir/mySubDir creation is done.
Neverthless, when I look in my device's file system I have no desired directories created... besides it a strange directory, called .mtp, was created, void, at system root.尽管如此,当我查看设备的文件系统时,我没有创建所需的目录......除此之外,在系统根目录下创建了一个名为 .mtp 的奇怪目录,该目录无效。
My goal is create and read files to/from /com.mydomain.mayapp/files/profile/images directory.我的目标是在 /com.mydomain.mayapp/files/profile/images 目录中创建和读取文件。 My code is based on a sample provided (in the end of the page) in Sample Link Followed ;我的代码基于Sample Link Followed 中提供的示例(在页面末尾); I am using Cordova.File plugin, version 4.1.0, in an Intel XDK hybrid app project.我在英特尔 XDK 混合应用项目中使用 Cordova.File 插件,版本 4.1.0。
I have the necessary android.permission.WRITE_EXTERNAL_STORAGE
permission defined.我定义了必要的android.permission.WRITE_EXTERNAL_STORAGE
权限。
Can someone point me in the right direction?有人可以指出我正确的方向吗? All advices are welcome... thanks in advance.欢迎所有建议......提前致谢。
Another document that I found very useful is here: cordova-plugin-file我发现另一个非常有用的文件在这里: cordova-plugin-file
according to this document:根据这份文件:
cordova.file.dataDirectory - Persistent and private data storage within the application's sandbox using internal memory ( on Android, if you need to use external memory, use .externalDataDirectory ). cordova.file.dataDirectory - 使用内部存储器(在 Android 上,如果您需要使用外部存储器,请使用 .externalDataDirectory )在应用程序沙箱中的持久和私有数据存储。 On iOS, this directory is not synced with iCloud (use .syncedDataDirectory).在 iOS 上,此目录不与 iCloud 同步(使用 .syncedDataDirectory)。 (iOS, Android, BlackBerry 10, windows) (iOS、Android、黑莓 10、Windows)
The directories that you are writting, are inside data/data folders, which belongs only to your app, and can't be accessed thought the device file system.您正在写入的目录位于 data/data 文件夹内,仅属于您的应用程序,无法通过设备文件系统访问。
If you want to use public folders, check this table如果要使用公用文件夹,请查看此表
https://github.com/apache/cordova-plugin-file#android-file-system-layout https://github.com/apache/cordova-plugin-file#android-file-system-layout
And choose a folder that don't be private.并选择一个非私人文件夹。
For example: externalApplicationStorageDirectory例如:externalApplicationStorageDirectory
Happy coding!快乐编码!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.