junerockwell
junerockwell

Reputation: 848

Know when to use cordova.file.externalRootDirectory in Android

cordova.file.externalRootDirectory will always exist and the app will think that there is an SD card even when there isn't an SD card. So in turn, files downloaded to cordova.file.externalRootDirectory won't exist. How can I be sure when to use cordova.file.externalRootDirectory in Android? If there is no SD card for my files to successfully be downloaded into, I want to use the cordova.file.dataDirectory. Is there a work-around for this?

Upvotes: 2

Views: 4363

Answers (1)

eb1
eb1

Reputation: 2947

Not sure if you've already found an answer for this -- if you haven't, you can take a look at this answer here. The code there iterates through a list of cordova.file.<xxx> items, listing the filenames (and recursing into subdirectories). If you are planning on listing directory contents, you could do something similar for just cordova.file.externalRootDirectory and cordova.file.datadirectory.

However, if you are testing for the existence of an SD card -- say to write to it -- you would just need check to see if there are any entries for cordova.file.externalRootDirectory (just check to see if entries.length > 0). If there are any, you could assume that there is an SD card installed.

Upvotes: 1

Related Questions