Edit: This was user error (sorry). I have answered it below.
I am developing an application that needs to access data on the sd card. When I run on my development device (an odroid with Android 2.1) I have root access and can construct the path using:
File sdcard = Environment.getExternalStorageDirectory();
String path = sdcard.getAbsolutePath() + File.separator + "mydata"
File data = new File(path);
File[] files = data.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
return filename.toLowerCase().endsWith(".xyz");
}});
However, when I install this on a phone (2.1) where I do not have root access I get files == null. I assume this is because I do not have the right permissions to read the data from the sd card. I also get files == null when just trying to list files on /sdcard. So the same applies without my constructed path.
Also, this app is not intended to be distributed through the app store and is needs to use data copied separately to the sd card so this is a real use-case. It is too much data to put in res/raw (I have tried, it did not work).
I have also tried adding:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
to the manifest, even though I only want to read the sd card, but it did not help. I have not found a permission type for reading the storage.
There is probably a correct way to do this, but I haven't been able to find it. Any hints would be useful.