Skip to content

Instantly share code, notes, and snippets.

@chris-piekarski
Created August 31, 2013 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-piekarski/6400633 to your computer and use it in GitHub Desktop.
Save chris-piekarski/6400633 to your computer and use it in GitHub Desktop.
Android Read/Write External Storage
//From AOSP Doc
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
/* Checks if external storage is available for read and write */
public boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
/* Checks if external storage is available to at least read */
public boolean isExternalStorageReadable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state) ||
Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
return true;
}
return false;
}
@chris-piekarski
Copy link
Author

The system uid can't access the SD card. You need to run the code doing the access as a different uid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment