Is it possible to read data that has been separately copied to Android SD card without getting root?

Edit: It was a user error (sorry). I answered below.

I am developing an application that needs to access data on an SD card. When I start my development device (odroid with Android 2.1) I have root access and can build 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 don't have root access, I get files == null. I assume this is because I do not have permission to read data from the SD card. I also get files == null when I just try to list files to / sdcard. The same goes for my built path.

Also, this app is not intended to be distributed via app store and must use data copied separately to SD card, so this is a real use case. Too much data to input res / raw (I tried it, it didn't work).

I also tried to add:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

      

into the manifest, although I only want to read the SD card, but it didn't help. I didn't find the type of permission to read the repository.

There is probably a correct way to do this, but I couldn't find one. Any hints would be helpful.

+2


a source to share


1 answer


So, I just spent half an hour writing this question and then unplugged my phone and plugged it in without setting it as a drive.

This was the problem. It works now.



Sorry for wasting my time.: /

+1


a source







All Articles