Material-File-Picker is a simple file picker for Android based on Material Design. The picker can be used to select files, directories or both. You can also decide what kind of files user will be able to select.
- Material Design
- Ability to select files
- Ability to select directories
- Ability to select both (files and directories)
- Ability to select specific file types
- Ability to decide which root directory user can explore
-External storages in Android 5+ isn’t currently supported.
Make sure you have defined the jcenter() repository in project's build.gradle file:
allprojects {
repositories {
jcenter()
}
}
Add the dependency to module's build.gradle file:
dependencies {
compile 'com.applandeo:material-file-picker:1.0.0'
}
Enable data binding in module's build.gradle file:
dataBinding {
enabled = true
}
Add to your java code:
new FilePicker.Builder(this, new OnSelectFileListener() {
@Override
public void onSelect(File file) {
…
}
});
The OnSelectFileListener returns standard Java File object.
new FilePicker.Builder(this, listener)
.hideFiles(true)
.show();
new FilePicker.Builder(this, listener)
.fileType(FileType.IMAGE)
.show();
Other file types: APK
, ARCHIVE
, BOOK
, DOCUMENT
, IMAGE
, MUSIC
, SHEET
, PDF
, PRESENTATION
, TEXT
and VIDEO
.
This method let you decide which directory user will see after picker opening:
new FilePicker.Builder(this, listener)
.directory("/storage/sdcard/MyFiles")
.show();
If you don't set this parameter, picker automatically view Download directory.
This method let you decide how far user can go up in the directories tree:
new FilePicker.Builder(this, listener)
.mainDirectory("/storage")
.show();
If you don't set this parameter, picker automatically set the main internal storage.
Use FilePicker.STORAGE_PERMISSIONS
to check if user granted storage permissions for the picker:
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED
&& requestCode == FilePicker.STORAGE_PERMISSIONS) {
...
}
}
You don't have to add permissions tag to your AndroidManifest.xml.
Simply use standard material color tags in your XML file where you store your colours. Picker automatically use them to adjust to your application.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
- Initial build
It would be great if you decide to use our component in your project. It’s open source, feel free. Write to us at [email protected] if you want to be listed and we will include your app in our repo. If you have any questions or suggestions just let us know.
Copyright 2017, Applandeo sp. z o.o.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.