0

I am trying to make a file browser app. So I want to begin with displaying something like this.

enter image description here

But I can not reach my SD card's path. I used this method

String path = Environment.getExternalStorageDirectory();

In the documentation here It says:

Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.

The problem is I can reach to the device storage but I can't reach to my SD card's path. Does anyone know how to get that path?

gunescelil
  • 313
  • 1
  • 23
  • 1
    You do not have arbitrary filesystem access to [removable storage](https://commonsware.com/blog/2014/04/09/storage-situation-removable-storage.html). – CommonsWare Jul 01 '16 at 11:24
  • you can read all types of directory using Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_ALARMS); – Hamza Mehmood Jul 01 '16 at 11:57

1 Answers1

3

 // Access the built-in SD card
 private String getInnerSDCardPath() {
  return Environment.getExternalStorageDirectory().getPath();
 }

 // Access to external SD card
 private List<String> getExtSDCardPath() {
  List<String> pathList = new ArrayList<String>();
  try {
   Runtime runtime = Runtime.getRuntime();
   Process proc = runtime.exec("mount");
   BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
   String line;
   while ((line = bufferedReader.readLine()) != null) {
    if (line.contains("extSdCard")) {
     String[] arr = line.split(" ");
     String path = arr[1];
     File file = new File(path);
     if (file.isDirectory()) {
      pathList.add(path);
     }
    }
   }
   bufferedReader.close();
  } catch (Exception e) {
   e.printStackTrace();
  }
  return pathList;
 }

I hope it can help you.

iOnesmile
  • 99
  • 4