Created
August 31, 2013 21:04
-
-
Save chris-piekarski/6400633 to your computer and use it in GitHub Desktop.
Android Read/Write External Storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The system uid can't access the SD card. You need to run the code doing the access as a different uid.