Advertisement
Guest User

Untitled

a guest
Jul 29th, 2013
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. /**
  2. * Checks if storage is available for our use.
  3. *
  4. * @return true if storage is available and writeable
  5. */
  6. public static boolean isStorageAvailable() {
  7. boolean mExternalStorageAvailable;
  8. boolean mExternalStorageWriteable;
  9. String state = Environment.getExternalStorageState();
  10.  
  11. if (Environment.MEDIA_MOUNTED.equals(state)) {
  12. // We can read and write the media
  13. mExternalStorageAvailable = mExternalStorageWriteable = true;
  14. } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
  15. // We can only read the media
  16. mExternalStorageAvailable = true;
  17. mExternalStorageWriteable = false;
  18. } else {
  19. // Something else is wrong. It may be one of many other states, but
  20. // all we need to know is we can neither read nor write
  21. mExternalStorageAvailable = mExternalStorageWriteable = false;
  22. }
  23.  
  24. Ln.i(mExternalStorageAvailable ? "Storage available" : "Storage Unavailable");
  25. Ln.i(mExternalStorageWriteable ? "Storage writeable" : "Storage not writeable");
  26.  
  27. return (mExternalStorageAvailable && mExternalStorageWriteable);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement