For my app, I have a fairly large database that needs to be stored on the user\'s device. I plan to change this in the future. For now, however, I\'d like to store it to the
Yep, KitKat now provides APIs for interacting with secondary external storage devices:
The new Context.getExternalFilesDirs()
and Context.getExternalCacheDirs()
methods can return multiple paths, including both primary and secondary devices. You can then iterate over them and check Environment.getStorageState()
and File.getFreeSpace()
to determine the best place to store your files. These methods are also available on ContextCompat
in the support-v4 library.
Also note that if you're only interested in using the directories returned by Context
, you no longer need the READ_
or WRITE_EXTERNAL_STORAGE
permissions. Going forward, you'll always have read/write access to these directories with no additional permissions required.
Apps can also continue working on older devices by end-of-lifing their permission request like this: