AndroidFilePicker

It doesn’t have a name like Rocky, Cosmos or Peppa. Android File Picker is, as its name suggests, a local File Picker framework. Some of his characteristics are described below:

  • inActivityFragmentIn the start
    • Start with a line of code
  • Browse all files in local storage
    • Customize the root directory
    • Built-in default file types and file discriminators
    • Or you can implement file types yourself
  • Custom list filters
    • Just want to show pictures (or video, audio……) ? No problem!
    • Of course, you can show only folders
  • The customitemClick events: Just implement the listener
  • Four built-in themes and custom themes
  • There are more features to explore on your own (?)
Rail Style (default) Reply Style Crane Style Shrine Style

Download the use

  1. Add dependencies to your project

Now the project build.gradle configuration file adds the repository:

allprojects {
    repositories {
	    ...
    	maven { url 'https://jitpack.io' }
    }
}
Copy the code

Then add dependencies to the profile of the submodule (app) :

dependencies {
    implementation 'me.rosuh:AndroidFilePicker:latest_version'
}
Copy the code

Replace latest_version with the latest version

use

permissions

This library requires two permissions:

  • android.permission.READ_EXTERNAL_STORAGE
  • android.permission.WRITE_EXTERNAL_STORAGE

If you do not grant the permission in advance, the library will automatically apply for it.

Come into use (Kotlin)

A simple chain call:

FilePickerManager
        .from(this@SampleActivity)
        .forResult(FilePickerManager.REQUEST_CODE)
Copy the code

Now you’ve taken off 🛩️… (Really only two lines)

If you use Java, you only need to add one. INSTANCE can be used:

FilePickerManager.INSTANCE
                .from(this)
                .forResult(FilePickerManager.REQUEST_CODE);
Copy the code

To get the results

Get results: onActivityResult receive a message, and then call FilePickerManager. ObtainData () get saved data, the result is the path of the selected file list (ArrayList < String > ())

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."Didn't choose anything.", Toast.LENGTH_SHORT).show()
            }
        }
    }
}
Copy the code

Obfuscation Rules (0.5.1 and earlier)

-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
-keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler {}
-keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {}

-keepclassmembernames class kotlinx.** {
    volatile <fields>;
}

Copy the code

Starting with 0.5.2, we removed the coroutine library and implemented it using native threads, so there was no confusion.

More examples

Why don’t you read my flight manual?

Or want to see the theme color scheme?

Functions & Features

  1. Chain calls
  2. Default selected implementation
    • Click on the entry (item) No default implementation
    • Click on theCheckBoxFor the selected
    • Long press an item to change the checked status: checked/unchecked
  3. Built-in four theme color schemes + customizable color schemes
    • View the theme color schematic, and callsetTheme()Pass in a custom theme
  4. Multiple file types are implemented by default
    • implementationIFileTypeInterface to implement your file type
    • implementationAbstractFileTypeAbstract class to implement your file type discriminator
  5. Exposes the file filtering interface
    • implementationAbstractFileFilterAbstract class to customize your own file filters so you can control the display of the file list
  6. Multiple configurable options
    1. Whether to ignore folders when selected
    2. Whether to show hidden folders (with symbols.If it begins, it is regarded as hidden file or hidden folder.)
    3. You can configure the text of the navigation bar, default display, multi-select text, unselect text, and the default name of the root directory
  7. Public entries (itemSelect the listener to customize the implementation of the click on the item

Part of the source code

Look here.

Log

Update Log

TODO

TODO


Special Thanks To:

  • *1 @whichName
  • BRVAH
  • Matisse
  • Default icon author Shulk
  • The theme color
  • Empty icon made by freepik from www.flaticon.com