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

Commit

Permalink
Use FileProvider to transform URIs in results
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Oct 22, 2016
1 parent 8fb5579 commit 101aa70
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.support.annotation.NonNull;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.support.v4.content.Loader;
import android.support.v7.util.SortedList;
import android.support.v7.widget.util.SortedListAdapterCallback;
Expand Down Expand Up @@ -196,7 +197,10 @@ public File getRoot() {
@NonNull
@Override
public Uri toUri(@NonNull final File file) {
return Uri.fromFile(file);
return FileProvider
.getUriForFile(getContext(),
getContext().getApplicationContext().getPackageName() + ".provider",
file);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions library/src/main/res/xml/nnf_provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<root-path
name="root"
path="." />
</paths>
10 changes: 10 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
android:label="@string/title_activity_no_nonsense_file_picker"/>

<!-- SD-card pickers -->
<!-- You must define a fileprovider for the sd-card pickers -->
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/nnf_provider_paths"/>
</provider>
<activity
android:name="com.nononsenseapps.filepicker.FilePickerActivity"
android:label="@string/title_activity_no_nonsense_file_picker"
Expand Down

0 comments on commit 101aa70

Please sign in to comment.