Android File Picker🛩️
Well, it doesn’t have a name like Rocky, Cosmos or Fish. Android File Picker, like its name, is a local file selector framework. Some of his characteristics are described below:
- Launcher in Activity or Fragment
- Start with a single line of code
- Browse and select all files in local storage
- Custom Root path to start
- Built-in default file type and file discriminator
- Or you can implement the file type yourself
- Built in Single Choice mode and Multiple Choice mode.
- Custom list filter
- Just want to show pictures(Or videos, audio…)? No problem!
- Of course, you can just display the folder
- Custom item click event: only need to implement the listener
- Apply different themes, including four built-in themes and custom themes
- More to find out yourself
Rail Style(default) | Reply Style | Crane Style | Shrine Style |
---|---|---|---|
Version Compatibility
It depends on your targetAPI.
targetAPI <= 28
, no problem at all ;)targetAPI == 29
, please enablerequestLegacyExternalStorage
feature for your project : DtargetAPI == 29
- When running on Android 11 and above, only media files (images, audio and video) can be read, but nothing else can be accessed (e.g. PDF documents, apk binary files, etc.)
Please check out this issue: All About Scope Storage.
Download
Gradle:
In your project build.gradle
:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
In your module build.gradle
:
dependencies {
implementation 'me.rosuh:AndroidFilePicker:$latest_version'
}
This lib now support AndroidX, check the version below.
Check out releases page to see more versions.
Usage 📑
Permission
The library requires one permissions:
android.permission.READ_EXTERNAL_STORAGE
If you do not have permission to apply, this framework will check and apply at startup.
Launch 🚀
FilePickerManager
.from(context)
.forResult(FilePickerManager.REQUEST_CODE)
Receive Result
In onActivityResult()
callback of the starting Activity
or Fragment
:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
FilePickerManager.instance.REQUEST_CODE -> {
if (resultCode == Activity.RESULT_OK) {
val list = FilePickerManager.instance.obtainData()
// do your work
} else {
Toast.makeText(this@SampleActivity, "You didn't choose anything~", Toast.LENGTH_SHORT).show()
}
}
}
}
The result is a path list of the selected file (ArrayList<String>()
).
Docs
Special Thanks To:
- whichName
- Matisse
- Default Icon Author Shulk
- Theme Color
- Empty icon made by freepik from www.flaticon.com