MaterialFilePicker

Additional

Language
Java
Version
N/A
Created
Oct 23, 2015
Updated
May 4, 2020
Owner
  (nbsp-team)
Contributors
Dima Merkurev (dimorinny)
Nickolay Chameev (lukaville)
Asha (ashqal)
Artem Nikitin (artemnikitin)
Daniel Morales (GrenderG)
Tomáš Šůstek (frogggias)
Diego Francisco Concepción (costular)
frankyxcs
owniz
Pranav Raj Singh Chauhan (prscX)
Asad@AJ (Asad-Khan-Aasanjobs)
11
Activity
Badge
Generate
Download
Source code
APK file

Announcement

Material File Picker

Material file picker library for Android

Using

Add repository url and dependency in application module gradle file:

repositories {
    jcenter()
}

dependencies {
    implementation 'com.nbsp:materialfilepicker:1.9.1'
}

Open file picker:

MaterialFilePicker()
    // Pass a source of context. Can be:
    //    .withActivity(Activity activity)
    //    .withFragment(Fragment fragment)
    //    .withSupportFragment(androidx.fragment.app.Fragment fragment)
    .withActivity(this)
    // With cross icon on the right side of toolbar for closing picker straight away
    .withCloseMenu(true)
    // Entry point path (user will start from it)
    .withPath(alarmsFolder.absolutePath)
    // Root path (user won't be able to come higher than it)
    .withRootPath(externalStorage.absolutePath)
    // Showing hidden files
    .withHiddenFiles(true)
    // Want to choose only jpg images
    .withFilter(Pattern.compile(".*\\.(jpg|jpeg)$"))
    // Don't apply filter to directories names
    .withFilterDirectories(false)
    .withTitle("Sample title")
    .withRequestCode(FILE_PICKER_REQUEST_CODE)
    .start()

Override on activity result:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == 1 && resultCode == RESULT_OK) {
        String filePath = data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH);
        // Do anything with file
    }
}

Runtime permissions:

You should handle runtime permissions in activity, from what you called Material File Picker. Look here for example code.

Third Party Bindings

React Native

You may now use this library with React Native via the module here