|
6 | 6 | * [Overview](#overview) |
7 | 7 | + [Java Compatibility](#java-compatibility) |
8 | 8 | * [Terminology](#terminology) |
| 9 | +* [Check Accessible Paths](#check-accessible-paths) |
9 | 10 | * [Read Files](#read-files) |
10 | 11 | + [`DocumentFileCompat`](#documentfilecompat) |
11 | 12 | - [Example](#example) |
@@ -65,6 +66,35 @@ Simple Storage is built in Kotlin. Follow this [documentation](JAVA_COMPATIBILIT |
65 | 66 | * Storage Permission – related to [runtime permissions](https://developer.android.com/training/permissions/requesting) |
66 | 67 | * Storage Access – related to [URI permissions](https://developer.android.com/reference/android/content/ContentResolver#takePersistableUriPermission(android.net.Uri,%20int)) |
67 | 68 |
|
| 69 | +## Check Accessible Paths |
| 70 | + |
| 71 | +To check whether you have access to particular paths, call `DocumentFileCompat.getAccessibleAbsolutePaths()`. The results will look like this in breakpoint: |
| 72 | + |
| 73 | +") |
| 74 | + |
| 75 | +All paths in those locations are accessible via functions `DocumentFileCompat.from*()`, otherwise your action will be denied by the system if you want to |
| 76 | +access paths other than those. Functions `DocumentFileCompat.from*()` (next section) will return null as well. On API 28-, you can obtain it by requesting |
| 77 | +the runtime permission. For API 29+, it is obtained automatically by calling `SimpleStorageHelper#requestStorageAccess()` or |
| 78 | +`SimpleStorageHelper#openFolderPicker()`. The granted paths are persisted by this library via `ContentResolver#takePersistableUriPermission()`, |
| 79 | +so you don't need to remember them in preferences: |
| 80 | +```kotlin |
| 81 | +buttonSelectFolder.setOnClickListener { |
| 82 | + storageHelper.openFolderPicker() |
| 83 | +} |
| 84 | + |
| 85 | +storageHelper.onFolderSelected = { requestCode, folder -> |
| 86 | + // tell user the selected path |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +In the future, if you want to write files into the granted path, use `DocumentFileCompat.fromFullPath()`: |
| 91 | +```kotlin |
| 92 | +val grantedPaths = DocumentFileCompat.getAccessibleAbsolutePaths(this) |
| 93 | +val path = grantedPaths.values.firstOrNull()?.firstOrNull() ?: return |
| 94 | +val folder = DocumentFileCompat.fromFullPath(this, path, requiresWriteAccess = true) |
| 95 | +val file = folder?.makeFile(this, "notes", "text/plain") |
| 96 | +``` |
| 97 | + |
68 | 98 | ## Read Files |
69 | 99 |
|
70 | 100 | In Simple Storage, `DocumentFile` is used to access files when your app has been granted full storage access, |
|
0 commit comments