Skip to content

Commit

Permalink
Use FileProvider to get file URI for API 24+ (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
csoni111 authored and cpg committed Oct 17, 2017
1 parent 041f4f7 commit 25149de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/main/java/org/amahi/anywhere/util/Downloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import android.support.v4.content.FileProvider;

import org.amahi.anywhere.bus.BusProvider;
import org.amahi.anywhere.bus.FileDownloadFailedEvent;
Expand Down Expand Up @@ -114,7 +115,13 @@ private void finishDownloading() {
String downloadUri = downloadInformation.getString(
downloadInformation.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));

BusProvider.getBus().post(new FileDownloadedEvent(Uri.parse(downloadUri)));
if (downloadUri.substring(0, 7).matches("file://")) {
downloadUri = downloadUri.substring(7);
}
File file = new File(downloadUri);
Uri contentUri = FileProvider.getUriForFile(context, "org.amahi.anywhere.fileprovider", file);

BusProvider.getBus().post(new FileDownloadedEvent(contentUri));
} else {
BusProvider.getBus().post(new FileDownloadFailedEvent());
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/res/xml/file_paths.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
<paths>
<external-path
name="user_images"
path="Android/data/org.amahi.anywhere/files/Pictures" />
</paths>
path="Android/data/org.amahi.anywhere/files/Pictures"/>
<external-path
name="user_downloads"
path="Android/data/org.amahi.anywhere/files/Download"/>
</paths>

0 comments on commit 25149de

Please sign in to comment.