How do i know if there are internal and external storage in android pragmatically? does anyone how to know how to check both internal and external storage
thanks in advance
The method getExternalStorageState() is used to determine the state of mounted storage media such as SD Card is missing, read-only or readable, and writable. Below is the code snippet which we will use to check the availability of external storage.
Your app's portion of internal storage will be on the /data/ partition. Exactly where depends upon the account that is running your app (Android 4.2+ supports multiple accounts per device). The primary device account will have your app's portion of internal storage be at /data/data/your.
it's already explained in android documentation.
Code taken from documentation
boolean mExternalStorageAvailable = false; boolean mExternalStorageWriteable = false; String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { // We can read and write the media mExternalStorageAvailable = mExternalStorageWriteable = true; } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // We can only read the media mExternalStorageAvailable = true; mExternalStorageWriteable = false; } else { // Something else is wrong. It may be one of many other states, but all we need // to know is we can neither read nor write mExternalStorageAvailable = mExternalStorageWriteable = false; }
I wrote a little class for that checking the storage state. Maybe it's of some use for you.
UPDATE: Cleaned up code, removed comments and made class static.
import android.os.Environment; public class StorageHelper { private static boolean externalStorageReadable, externalStorageWritable; public static boolean isExternalStorageReadable() { checkStorage(); return externalStorageReadable; } public static boolean isExternalStorageWritable() { checkStorage(); return externalStorageWritable; } public static boolean isExternalStorageReadableAndWritable() { checkStorage(); return externalStorageReadable && externalStorageWritable; } private static void checkStorage() { String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) { externalStorageReadable = externalStorageWritable = true; } else if (state.equals(Environment.MEDIA_MOUNTED) || state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) { externalStorageReadable = true; externalStorageWritable = false; } else { externalStorageReadable = externalStorageWritable = false; } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With