FilePicker is a small and fast file selector library that is constantly evolving with the goal of rapid integration, high customization, and configurability~
If you're using 0.x
version, checkout the README_0.x file.
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:
Rail | Reply | Crane | Shrine |
---|---|---|---|
It depends on your targetAPI.
targetAPI > 33
, may be you are finding photo picker
targetAPI == 33
targetAPI <= 33
android:requestLegacyExternalStorage="true"
in your AndroidManifest.xml
fileandroid.permission.READ_EXTERNAL_STORAGE
permission by your ownIn your project build.gradle
:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
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.
You should request permission by yourself, this lib will not request permission for you. See Version Compatibility for more details.
FilePickerManager
.from(context)
.forResult(FilePickerManager.REQUEST_CODE)
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>()
).