0

I´m developing in Ecilpse ADT (for external issues), and I have a device with Android. It's an EPD (electronic paper) with Android 4.0.4 (Ice Cream Sandwich), and the device has one microSD card, but I can't access it programmatically. I need to read some images inside it.

As a test I have tried with the following code and other variations, and I have not been successful:

    File sdcard = Environment.getExternalStorageDirectory();

    File file = new File(sdcard,"prueba_sd.txt");

    StringBuilder text = new StringBuilder();

    try {
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line;

        while ((line = br.readLine()) != null) {
            text.append(line);
            text.append('\n');
        }
        br.close();

        Log.i("Ficheros", "It works!");

    }
    catch (Exception ex) {
        Log.e("Ficheros", "Doesnt work");
    }

Additional this is the structure of the DDMS perspective:

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user2091725
  • 63
  • 1
  • 3
  • 8
  • Your code should be able to read that file. Dont tell it does not. But it will not be on SD card. You should add code to check if the file exists. Use `file.exists()`. Why dont you try to create/write a file instead? What is the value of file.getAbsolurthePath()? – greenapps Feb 28 '17 at 16:30

2 Answers2

0

Environment.getExternalStorageDirectory() is for external storage, not removable storage. In Android 4.0.4, there was no API for working with removable storage. You would have to hard-code the fully-qualified path to the removable storage. For an app that you are just going to use yourself on this one device, hard-coding that path should be safe.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thx for your answer. Do you suggest something like this? String fileName = "/mnt/extsd/file.txt"; – user2091725 Feb 28 '17 at 17:17
  • @user2091725: Assuming that your screenshot reflects the actual filesystem on the device, then yes. Note that you might not have read access to that location, though. Prior to Android 4.4, removable storage worked however the device manufacturer wanted, and not all manufacturers allowed app developers to access it. – CommonsWare Feb 28 '17 at 17:35
0

There is not an API to get the micro-SD path. Try to use this answer and read the path of the removable storage from a system's file (/etc/vold.fstab).

Community
  • 1
  • 1
Massimo
  • 3,436
  • 4
  • 40
  • 68
  • Thx for your answer. I have reviewed the answer but what does this mean? -> fis = new FileInputStream(new File("/etc/vold.fstab")); specifically "/etc/vold.fstab" – user2091725 Feb 28 '17 at 17:19
  • the vold.fstab is the file in which you can find removable storage paths. That answer simply reads that file. – Massimo Feb 28 '17 at 17:24