I want to access the picture files in public folder in external storage. Here is my code:
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
java.io.File pictureDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
///storage/sdcard0/Pictures
boolean canRead = pictureDir.canRead();
//Above gives false
java.io.File[] picFiles = pictureDir.listFiles();
//null is returned for the file though I've atleast three picture files at this location
}
It gives me correct pointer to public folder, but canRead() method returns false. When I try listing the files under Picture directory, it gives me null.
Let me know if you need more details.
[UPDATE]
Permission in AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
[UPDATE 2] This looks like a device specific issue since it works fine on emulator.
You declare wrong permission in you AndroidManifest.xml. You are actually using external storage. From API 16 there is new permission that is required if you are using external storage:
http://developer.android.com/reference/android/Manifest.permission.html#READ_EXTERNAL_STORAGE
You can test your app with the permission enforced by either running your app on the Android Emulator when running Android 4.1 or higher, or enabling Protect USB storage under Developer options in the Settings app on a device running Android 4.1 or higher.
Probably in your device is set Protect USB storage in such case you need to use READ_EXTERNAL_STORAGE
permission. By the way WRITE_EXTERNAL_STORAGE
will cover READ_EXTERNAL_STORAGE
.