duyuxuan / MaterialFilePicker

Picking files since 2015

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Material File Picker Android Arsenal Download

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

About

Picking files since 2015

License:Apache License 2.0


Languages

Language:Java 79.9%Language:Kotlin 20.1%