Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check internal and external storage if exist

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

like image 392
oczdref Avatar asked Sep 30 '11 23:09

oczdref


People also ask

What is the method name to check external storage card status?

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.

Where is internal storage located?

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.


2 Answers

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; } 
like image 181
ariefbayu Avatar answered Oct 04 '22 04:10

ariefbayu


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;         }     }  } 
like image 34
kaolick Avatar answered Oct 04 '22 04:10

kaolick