Skip to content

Commit d9a5162

Browse files
committed
Updated README.md
1 parent e3bf3c7 commit d9a5162

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [Overview](#overview)
77
+ [Java Compatibility](#java-compatibility)
88
* [Terminology](#terminology)
9+
* [Check Accessible Paths](#check-accessible-paths)
910
* [Read Files](#read-files)
1011
+ [`DocumentFileCompat`](#documentfilecompat)
1112
- [Example](#example)
@@ -65,6 +66,35 @@ Simple Storage is built in Kotlin. Follow this [documentation](JAVA_COMPATIBILIT
6566
* Storage Permission – related to [runtime permissions](https://developer.android.com/training/permissions/requesting)
6667
* Storage Access – related to [URI permissions](https://developer.android.com/reference/android/content/ContentResolver#takePersistableUriPermission(android.net.Uri,%20int))
6768

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+
![Alt text](art/getAccessibleAbsolutePaths.png?raw=true "DocumentFileCompat.getAccessibleAbsolutePaths()")
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+
6898
## Read Files
6999

70100
In Simple Storage, `DocumentFile` is used to access files when your app has been granted full storage access,

art/getAccessibleAbsolutePaths.png

36.2 KB
Loading

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ kotlin.code.style=official
2323
GROUP=com.anggrayudi
2424
POM_ARTIFACT_ID=storage
2525
VERSION_NAME=1.5.4-SNAPSHOT
26-
RELEASE_SIGNING_ENABLED=false
26+
RELEASE_SIGNING_ENABLED=true
2727
SONATYPE_AUTOMATIC_RELEASE=true
2828
SONATYPE_HOST=DEFAULT
2929
POM_NAME=storage

0 commit comments

Comments
 (0)