Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
Use Utils.getFileForUri in Sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Oct 22, 2016
1 parent 983138d commit 9133681
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
16 changes: 1 addition & 15 deletions library/src/main/java/com/nononsenseapps/filepicker/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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());
}
}
}
Expand Down

0 comments on commit 9133681

Please sign in to comment.