android - Cordova File Plugin 创建的文件的位置在哪里?

标签 android cordova phonegap-plugins cordova-plugins

我用过Cordova File Plugin在移动设备上创建文件。下面是创建文件的代码:

window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function (dir) {
   alert(cordova.file.dataDirectory);
   dir.getFile("log.txt", { create: true }, function (file) {
          alert("got the file: "+ file.name + ', ' + file.fullPath);
   });
});

当我在我的安卓手机上部署应用程序时,文件会创建成功,但我在我的设备上找不到创建的文件。

虽然 cordova.file.dataDirectory 指向我设备上的 file:///data/data/io.cordova.myappId/files/ 路径,但 io.cordova.myappId 文件夹在 data>data 路径中不存在,但在 Android>data 路径中存在。顺便说一句,我检查了 storage>Android>data>io.Cordova.myappId>filesstorage>data>data 并且该文件不存在。

这是因为:

创建的文件位于另一个地方,那么我在哪里可以找到呢?

因为它是私有(private)的,而我的文件管理员无权访问它,所以我该如何更改权限设置以拥有公共(public)文件?

最佳答案

为什么在我的设备上找不到文件?

文件已成功创建,但我在我的设备上找不到该文件,因为 dataDirectory我指示创建文件的路径是私有(private)路径,我的设备文件管理器无权访问它(基于 this table )。其实dataDirectoryInternal Storage选项。

Internal Storage: Store private data on the device memory.

You can save files directly on the device's internal storage. By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). When the user uninstalls your application, these files are removed.(reference)

如何创建公共(public)文件?

因此,要在我的设备上创建一个可以使用文件管理器访问的文件,我必须使用以下公共(public)路径选项之一:externalDataDirectory .之前,我认为它是用于将文件存储在我手机上没有的外部 SD 卡上,所以我没有测试它。但是今天测试它,它在我的内部设备存储中创建文件 Android/data/<app-id>/files路径是公开的,我可以使用设备文件管理器访问它。

其实是internal这个词和 externalexternal storage 时误导了我可以是可移动存储介质(例如 SD 卡)或内部(不可移动)存储 (reference)。

关于android - Cordova File Plugin 创建的文件的位置在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34694139/

相关文章:

java - 如何以编程方式删除用户安装的证书?

android - 如何将按钮的背景颜色重置为默认值?

javascript - 如何在输入文本上显示 NFC 扫描结果

javascript - 检查 Phonegap 应用程序连接

javascript - Phonegap/Cordova 社交共享 js shareViaFacebook 无法在 Windows Phone 中工作

android - 在 Phonegap 的 inappbrowser 中禁用缩放按钮

android - 解码位图返回 null

android - 将菜单背景设置为不透明

javascript - Cordova 错误 : Refused to execute inline script because it violates the following Content Security Policy directive

html - Phonegap 文件传输错误