Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
WIP - better way to get the case of /.../documents/... right
Browse files Browse the repository at this point in the history
  • Loading branch information
Catfriend1 committed Jun 29, 2018
1 parent 9906514 commit c786e35
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.storage.StorageManager;
import android.provider.DocumentsContract;
import android.support.annotation.Nullable;
Expand All @@ -29,7 +30,6 @@ private FileUtils() {

private static final String PRIMARY_VOLUME_NAME = "primary";
private static final String HOME_VOLUME_NAME = "home";
private static final String DOCUMENTS_FOLDER_NAME = "documents";

@Nullable
@TargetApi(21)
Expand Down Expand Up @@ -80,6 +80,7 @@ public static String getAbsolutePathFromTreeUri(Context context, @Nullable final
}

@SuppressLint("ObsoleteSdkInt")
@TargetApi(21)
private static String getVolumePath(final String volumeId, Context context) {
if (!isCompatible) {
Log.e(TAG, "getVolumePath called on unsupported API level");
Expand Down Expand Up @@ -107,7 +108,8 @@ private static String getVolumePath(final String volumeId, Context context) {
// Return path if the correct volume corresponding to volumeId was found.
return (String) getPath.invoke(storageVolumeElement);
} else if (isHomeVolume) {
return (String) getPath.invoke(storageVolumeElement) + File.separator + DOCUMENTS_FOLDER_NAME;
// Reading the environment var avoids hard coding the case of the "documents" folder.
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath();
}
Log.d(TAG, "Skipping volume, uuid = '" + uuid + "', volumeId = '" + volumeId + "'");
}
Expand Down

0 comments on commit c786e35

Please sign in to comment.