From 9133681740284c4241b224a9f8f6fb119db1b847 Mon Sep 17 00:00:00 2001 From: Jonas Kalderstam Date: Sat, 22 Oct 2016 17:20:42 +0200 Subject: [PATCH] Use `Utils.getFileForUri` in Sample app --- .../com/nononsenseapps/filepicker/Utils.java | 16 +--------------- .../filepicker/sample/NoNonsenseFilePicker.java | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/library/src/main/java/com/nononsenseapps/filepicker/Utils.java b/library/src/main/java/com/nononsenseapps/filepicker/Utils.java index aaa86a53..897df54a 100644 --- a/library/src/main/java/com/nononsenseapps/filepicker/Utils.java +++ b/library/src/main/java/com/nononsenseapps/filepicker/Utils.java @@ -63,21 +63,7 @@ public static String appendPath(@NonNull String first, */ @NonNull public static File getFileForUri(@NonNull Uri uri) { - return getFileForUriString(uri.getEncodedPath()); - } - - /** - * Convert a uri generated by a fileprovider, like content://AUTHORITY/ROOT/actual/path - * to a file pointing to file:///actual/path - * - * Note that it only works for paths generated with `ROOT` as the path element. This is done if - * nnf_provider_paths.xml is used to define the file provider in the manifest. - * - * @param path string decoded from a URI provided by a FileProvider - * @return Corresponding {@link File} object - */ - @NonNull - public static File getFileForUriString(@NonNull String path) { + String path = uri.getEncodedPath(); final int splitIndex = path.indexOf('/', 1); final String tag = Uri.decode(path.substring(1, splitIndex)); path = Uri.decode(path.substring(splitIndex + 1)); diff --git a/sample/src/main/java/com/nononsenseapps/filepicker/sample/NoNonsenseFilePicker.java b/sample/src/main/java/com/nononsenseapps/filepicker/sample/NoNonsenseFilePicker.java index f10b3cc5..0cf09b19 100644 --- a/sample/src/main/java/com/nononsenseapps/filepicker/sample/NoNonsenseFilePicker.java +++ b/sample/src/main/java/com/nononsenseapps/filepicker/sample/NoNonsenseFilePicker.java @@ -11,6 +11,7 @@ import android.content.ClipData; import android.content.Intent; import android.databinding.DataBindingUtil; +import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.util.Log; @@ -22,6 +23,7 @@ import com.dropbox.client2.android.AndroidAuthSession; import com.nononsenseapps.filepicker.AbstractFilePickerFragment; import com.nononsenseapps.filepicker.FilePickerActivity; +import com.nononsenseapps.filepicker.Utils; import com.nononsenseapps.filepicker.sample.databinding.ActivityNoNonsenseFilePickerBinding; import com.nononsenseapps.filepicker.sample.dropbox.DropboxFilePickerActivity; import com.nononsenseapps.filepicker.sample.dropbox.DropboxFilePickerActivity2; @@ -234,8 +236,10 @@ protected void onActivityResult(int requestCode, int resultCode, if (i > 0) { sb.append("\n"); } - // Returns Strings to workaround a bug in Android 7.0 Nougat - sb.append(clip.getItemAt(i).getText()); + Uri uri = clip.getItemAt(i).getUri(); + sb.append(CODE_SD == requestCode ? + Utils.getFileForUri(uri).toString() : + uri.toString()); } } @@ -250,13 +254,17 @@ protected void onActivityResult(int requestCode, int resultCode, if (sb.length() > 0) { sb.append("\n"); } - sb.append(path); + sb.append(CODE_SD == requestCode ? + Utils.getFileForUriString(path).toString() : + path); } } binding.text.setText(sb.toString()); } } else /* Single file mode */ { - binding.text.setText(data.getData().toString()); + binding.text.setText(CODE_SD == requestCode ? + Utils.getFileForUri(data.getData()).toString() : + data.getDataString()); } } }