iPaulPro / aFileChooser

[DEPRECATED] Android library that provides a file explorer to let users select files on external storage.
Apache License 2.0
1.79k stars 850 forks source link

ArrayIndexOutOfBoundsException in FileUtils#getPath if called with root of primary external storage #66

Open mtotschnig opened 9 years ago

mtotschnig commented 9 years ago

When the Uri content://com.android.externalstorage.documents/tree/primary%3A/document/primary%3A is fed into FileUtils#getPath, an ArrayIndexOutOfBoundsException is raised, because the docId for this URI is "primary:" and thus splitting this id on ":" gives an array with length 1

The following fixes the problem:

    if ("primary".equalsIgnoreCase(type)) {
      String path = Environment.getExternalStorageDirectory().getPath();
      if (split.length > 1) {
        path += "/" + split[1];
      }
      return path;
    }
kashban commented 9 years ago

Probably a pull request would be more appropriate to provide a solution.

Nice find though, I see those exceptions in my crash reports quite often. Thanks!