Is it possible to read data that has been separately copied to the Android sd card without having ro

Posted by icecream on Stack Overflow See other posts from Stack Overflow or by icecream
Published on 2010-05-04T13:55:37Z Indexed on 2010/05/04 13:58 UTC
Read the original article Hit count: 348

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.

© Stack Overflow or respective owner

Related posts about android

Related posts about android-sdk