You are on page 1of 13

ANDROID DATA

STORAGE
External Storage
WHAT IS EXTERNAL STORAGE

 Every Android device supports a shared "external storage" space


that you can use to save files.
 This space is called external because it's not a guaranteed to be
accessible—it is a storage space that users can mount to a
computer as an external storage device, and it might even be
physically removable (such as an SD card).
 Files saved to the external storage are world-readable and can
be modified by the user when they enable USB mass storage to
transfer files on a computer.
In general there are two types of External Storage:
 Primary External Storage: In built shared storage which is
“accessible by the user by plugging in a USB cable and mounting
it as a drive on a host computer”.
Example: When we say Nexus 5 32 GB.
 Secondary External Storage: Removable storage.
Example: SD Card
WHY EXTERNAL STORAGE?

Android has already provided efficient internal


storage for application, but still there is much
need for external storage under certain
circumstance.
1.Need more memory or disk space to save big
files;
2.Let data saved or generated in your
application be accessed by other applications;
3.Some saved data should not be deleted
although your application is uninstalled. For
example, pictures, videos downloaded by
your application.
SAVE A FILE ON AN EXTERNAL
STORAGE
REQUEST EXTERNAL STORAGE
PERMISSIONS
 To write to the public external storage, you must request the
WRITE_EXTERNAL_STORAGE permission in your manifest file:
REQUEST EXTERNAL STORAGE
PERMISSIONS
 If your app only needs to read the external storage (but not write to it),
then you need to declare the READ_EXTERNAL_STORAGE
permission:

 Beginning with Android 4.4 (API level 19), reading or writing files in
your app's private external storage directory—accessed using
getExternalFilesDir()—does not require the
READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE
permissions. So if your app supports Android 4.3 (API level 18) and
lower, and you want to access only the private external storage
directory, you should declare that the permission be requested only on
the lower versions of Android by adding the maxSdkVersion attribute:
VERIFY THAT EXTERNAL STORAGE
IS AVAILABLE
 the following methods are useful to determine the storage
availability:
VERIFY THAT EXTERNAL STORAGE
IS AVAILABLE
 the following methods are useful to determine the storage
availability:
DELETE A FILE

 Always delete files that your app no longer need. The most
straightforward way to delete a file is to call delete() on the File
object.
DELETE A FILE

 Always delete files that your app no longer need. The most
straightforward way to delete a file is to call delete() on the File
object.
ASSIGNMENT

 HOW TO (IN KOTLIN):


 Save to a public directory
 Save to a private directory

You might also like