文件下载cordovaFileTransfer:cordova.file.documentsDirectory is null

在Android平台上使用:$cordovaFileTransfer进行文件下载时提示:cordova.file.documentsDirectory is null,查了以下文档参照:http://ngcordova.com/docs/plugins/file/,

documentsDirectory是IOS平台的用法,在Android平台上没有此方法所以获取到null,解决方法:

通过使用:$cordovaDevice.getPlatform()获取应用平台,针对不同平台进行文件下载处理:

IOS使用:cordova.file.documentsDirectory

Android使用:cordova.file.externalRootDirectory

iOS File System Layout
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**
Android File System Layout
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

你可能感兴趣的:(Directory)