相关疑难解决方法(0)

为什么cordova.file.documentsDirectory为null?

我想在http://ngcordova.com/docs/plugins/fileTransfer/上使用cordova-plugin-file-transfer

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

var targetPath = cordova.file.documentsDirectory + "testImage.png";
Run Code Online (Sandbox Code Playgroud)

但是,此属性不存在.我已经登录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
}
Run Code Online (Sandbox Code Playgroud)

此外,我已经从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" />
Run Code Online (Sandbox Code Playgroud)

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

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

$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));
    });
Run Code Online (Sandbox Code Playgroud)

这是错误(格式化).

{
    "code": 1, …
Run Code Online (Sandbox Code Playgroud)

android angularjs cordova ionic-framework

4
推荐指数
1
解决办法
7223
查看次数

标签 统计

android ×1

angularjs ×1

cordova ×1

ionic-framework ×1