From fa030319ff606f93e26d00a0bab4e06272278222 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Sat, 23 Mar 2019 12:36:50 +0100 Subject: [PATCH] Suggest new folder creation on primary storage (fixes #376) (#379) if no external sdcard has been found. --- .../syncthingandroid/activities/FolderActivity.java | 5 +++++ .../com/nutomic/syncthingandroid/util/FileUtils.java | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderActivity.java index a31b7b88..fd421eb6 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderActivity.java @@ -327,6 +327,11 @@ public class FolderActivity extends SyncthingActivity { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); if (externalFilesDirUri != null) { intent.putExtra("android.provider.extra.INITIAL_URI", externalFilesDirUri); + } else { + android.net.Uri internalFilesDirUri = FileUtils.getInternalStorageRootUri(); + if (internalFilesDirUri != null) { + intent.putExtra("android.provider.extra.INITIAL_URI", internalFilesDirUri); + } } intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); intent.putExtra("android.content.extra.SHOW_ADVANCED", true); diff --git a/app/src/main/java/com/nutomic/syncthingandroid/util/FileUtils.java b/app/src/main/java/com/nutomic/syncthingandroid/util/FileUtils.java index c81b96a3..6b1b7acf 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/util/FileUtils.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/util/FileUtils.java @@ -217,6 +217,15 @@ public class FileUtils { return null; } + /** + * FileProvider does not support converting absolute paths + * to a "content://" Uri. As "file://" Uri has been blocked + * since Android 7+, we need to build the Uri manually. + */ + public static android.net.Uri getInternalStorageRootUri() { + return android.net.Uri.parse("content://com.android.externalstorage.documents/document/primary%3A"); + } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) private static String getVolumeIdFromTreeUri(final Uri treeUri) { final String docId = DocumentsContract.getTreeDocumentId(treeUri);