在Android平臺上使用:$cordovaFileTransfer進行文件下載時提示:cordova.file.documentsDirectory is null,查瞭如下文檔參照:http://ngcordova.com/docs/plugins/file/,android
documentsDirectory是IOS平臺的用法,在Android平臺上沒有此方法因此獲取到null,解決方法:ios
經過使用:$cordovaDevice.
getPlatform()獲取應用平臺,針對不一樣平臺進行文件下載處理:
app
IOS使用:cordova.file.documentsDirectorycode
Android使用:cordova.file.externalRootDirectoryorm
Device Path | cordova.file.* |
iosExtraFileSystems |
r/w? | persistent? | OS clears | sync | private |
---|---|---|---|---|---|---|---|
/var/mobile/Applications/<UUID>/ |
applicationStorageDirectory | - | r | N/A | N/A | N/A | Yes |
appname.app/ |
applicationDirectory | bundle | r | N/A | N/A | N/A | Yes |
www/ |
- | - | r | N/A | N/A | N/A | Yes |
Documents/ |
documentsDirectory | documents | r/w | Yes | No | Yes | Yes |
NoCloud/ |
- | documents-nosync | r/w | Yes | No | No | Yes |
Library |
- | library | r/w | Yes | No | Yes? | Yes |
NoCloud/ |
dataDirectory | library-nosync | r/w | Yes | No | No | Yes |
Cloud/ |
syncedDataDirectory | - | r/w | Yes | No | Yes | Yes |
Caches/ |
cacheDirectory | cache | r/w | Yes* | Yes*** | No | Yes |
tmp/ |
tempDirectory | - | r/w | No** |
Device Path | cordova.file.* |
AndroidExtraFileSystems |
r/w? | persistent? | OS clears | private |
---|---|---|---|---|---|---|
file:///android_asset/ |
applicationDirectory | r | N/A | N/A | Yes | |
/data/data/<app-id>/ |
applicationStorageDirectory | - | r/w | N/A | N/A | Yes |
cache |
cacheDirectory | cache | r/w | Yes | Yes* | Yes |
files |
dataDirectory | files | r/w | Yes | No | Yes |
Documents |
documents | r/w | Yes | No | Yes | |
<sdcard>/ |
externalRootDirectory | sdcard | r/w | Yes | No | No |
Android/data/<app-id>/ |
externalApplicationStorageDirectory | - | r/w | Yes | No | No |
cache |
externalCacheDirectry | cache-external | r/w | Yes | No** | No |
files |
externalDataDirectory | files-external | r/w |