FileAndFolderPicker
This is a library for create a picker in your android application. You can pick a single or multiple file. Also you can pick folder with it.
this library is compatible to androidx
Preview
Setup
The simplest way to use this library is to add the library as dependency to your build.
Gradle
Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
maven { url "https://maven.google.com" }
google()
jcenter()
maven { url 'https://jitpack.io' }
...
}
}
Step 2. Add the dependency
// builde.gradle(app level)
android{
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dataBinding {
enabled = true
}
}
dependencies {
implementation 'com.github.salehyarahmadi:FileAndFolderPicker:1.0.4'
}
Usage
Java
For select single file
if(permissionGranted()) {
SingleFilePickerDialog singleFilePickerDialog = new SingleFilePickerDialog(this,
() -> Toast.makeText(MainActivity.this, "Canceled!!", Toast.LENGTH_SHORT).show(),
files -> Toast.makeText(MainActivity.this, files[0].getPath(), Toast.LENGTH_SHORT).show());
singleFilePickerDialog.show();
}
else{
requestPermission();
}
For select multiple files
if(permissionGranted()) {
MultiFilePickerDialog multiFilePickerDialog = new MultiFilePickerDialog(this,
() -> Toast.makeText(MainActivity.this, "Canceled!!", Toast.LENGTH_SHORT).show(),
files -> Toast.makeText(MainActivity.this, files[0].getPath(), Toast.LENGTH_SHORT).show()
);
multiFilePickerDialog.show();
}
else{
requestPermission();
}
For select directory
if(permissionGranted()) {
DirectoryPickerDialog directoryPickerDialog = new DirectoryPickerDialog(this,
() -> Toast.makeText(MainActivity.this, "Canceled!!", Toast.LENGTH_SHORT).show(),
files -> Toast.makeText(MainActivity.this, files[0].getPath(), Toast.LENGTH_SHORT).show()
);
directoryPickerDialog.show();
}
else{
requestPermission();
}
Permissions
private boolean permissionGranted(){
return ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
&& ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
}
private void requestPermission(){
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
}
In all types, you receive an array of files. In case of single file and directory picker, you have to use index 0 of files array. But in multiple files picker you can use all indices of array.