Data Files and Storage: Licensed Under Creative Commons Attribution 2.5 License. All Rights Reserved
Data Files and Storage: Licensed Under Creative Commons Attribution 2.5 License. All Rights Reserved
This document is copyright (C) Marty Stepp and Stanford Computer Science.
Licensed under Creative Commons Attribution 2.5 License. All rights reserved.
Files and storage
● Android can read/write files from two locations:
– internal and external storage.
– Both are persistent storage; data remains after power-off / reboot.
<manifest ...>
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
</manifest>
Using external storage
● Methods to read/write external storage:
– getExternalFilesDir("name") -
returns "private" external directory for your app with the given name
– Environment.getExternalStoragePublicDirectory(name) -
returns public directory for common files like photos, music, etc.
● pass constants for name such as Environment.DIRECTORY_ALARMS,
DIRECTORY_DCIM, DIRECTORY_DOWNLOADS, DIRECTORY_MOVIES,
DIRECTORY_MUSIC, DIRECTORY_NOTIFICATIONS, DIRECTORY_PICTURES,
DIRECTORY_PODCASTS, DIRECTORY_RINGTONES