gpt4 book ai didi

android - 为什么 cordova.file.documentsDirectory 为空?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:42:47 24 4
gpt4 key购买 nike

我正在尝试在 http://ngcordova.com/docs/plugins/fileTransfer/ 处使用 cordova-plugin-file-transfer

指定下载位置的示例代码如下。

var targetPath = cordova.file.documentsDirectory + "testImage.png";

但是,这个属性不存在。我记录了 console.log(JSON.stringify(cordova.file)) 并得到以下输出(格式化)。

{
"applicationDirectory": "file:///android_asset/",
"applicationStorageDirectory": "file:///data/data/com.ionicframework.mobile379071/",
"dataDirectory": "file:///data/data/com.ionicframework.mobile379071/files/",
"cacheDirectory": "file:///data/data/com.ionicframework.mobile379071/cache/",
"externalApplicationStorageDirectory": "file:///storage/emulated/0/Android/data/com.ionicframework.mobile379071/",
"externalDataDirectory": "file:///storage/emulated/0/Android/data/com.ionicframework.mobile379071/files/",
"externalCacheDirectory": "file:///storage/emulated/0/Android/data/com.ionicframework.mobile379071/cache/",
"externalRootDirectory": "file:///storage/emulated/0/",
"tempDirectory": null,
"syncedDataDirectory": null,
"documentsDirectory": null,
"sharedDirectory": null
}

此外,我还遵循了此处的一些提示 https://cordova.apache.org/docs/en/dev/cordova-plugin-file/并使用以下更改修改了我的 config.xml。

<preference name="AndroidPersistentFileLocation" value="Internal" />
<preference name="iosPersistentFileLocation" value="Library" />
<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />
<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,root" />

此代码不是在模拟器或浏览器上运行,而是在真正的 Android 设备上运行。关于此属性为何为空的任何想法?

当我尝试下载文件时,我得到的只是一个错误。我的代码如下所示。

$cordovaFileTransfer.download(url, path, {}, true)
.then(function(result) {
console.log(JSON.stringify(result));
}, function(err) {
console.log(JSON.stringify(err));
}, function(progress) {
console.log(JSON.stringify(progress));
});

这是错误(格式化)。

{
"code": 1,
"source": "http://192.168.0.169/api/user/file/e95cdcfd541746b3b0721c992d756137",
"target": "IMG_20160224_030826.jpg",
"http_status": 200,
"body": null,
"exception": "/IMG_20160224_030826.jpg: open failed: EROFS (Read-only file system)"
}

关于我做错了什么的任何想法?如果 documentsDirectory 为 null,我应该使用哪个 cordova.file.*

最佳答案

据我检查 cordova 文件插件,cordova.file.documentsDirectory 对 Android 无效。

这是github中cordova file plugin官方文档中提到的描述:

"cordova.file.documentsDirectory - Files private to the app, but that are meaningful to other application (e.g. Office files). Note that for OSX this is the user's ~/Documents directory. (iOS, OSX)"

试用适用于 Android 的 cordova.file.externalDataDirectory 或 cordova.file.externalRootDirectory。希望对你有帮助

关于android - 为什么 cordova.file.documentsDirectory 为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36367973/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com