Giter Site home page Giter Site logo

zktzktzkt / androidfilepicker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rosuh/androidfilepicker

0.0 0.0 0.0 1.56 MB

文件选择器 - FilePicker is a small and fast file selector library that is constantly evolving with the goal of rapid integration, high customization, and configurability~

Home Page: https://afp.rosuh.me

License: MIT License

Java 2.82% Kotlin 97.18%

androidfilepicker's Introduction

Banner

Android File Picker🛩️

中文简体

Well, it doesn't have a name like Rocky, Cosmos or Fish. Android File Picker, like its name, is a local file selector framework. Some of his characteristics are described below:

  • Launcher in Activity or Fragment
    • Start with a single line of code
  • Browse and select all files in local storage
    • Custom Root path to start
    • Built-in default file type and file discriminator
    • Or you can implement the file type yourself
  • Built in Single Choice mode and Multiple Choice mode.
  • Custom list filter
    • Just want to show pictures(Or videos, audio...)? No problem!
    • Of course, you can just display the folder
  • Custom item click event: only need to implement the listener
  • Apply different themes, including four built-in themes and custom themes
  • More to find out yourself
Rail Style(default) Reply Style Crane Style Shrine Style

Compatibility

It depends on your targetAPI:

  • targetAPI <= 28, you are fine ;)
  • targetAPI == 29, please enable requestLegacyExternalStorage feature for your project :D
  • targetAPI >= 30, don't use this lib. We don't support scope storage for now :(
    • Unless Google release new external permission or other new feature, we would not consider support scope storage. (or says: "I can't do this")
    • Or, ofcouse, you are welcome for give us some ideas. Just create a new issues.

Download

Gradle:

In your project build.gradle:

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

In your module build.gradle:

dependencies {
    implementation 'me.rosuh:AndroidFilePicker:$latest_version'
}

This lib now support AndroidX, check the version below.

Check out releases page to see more versions.

Usage 📑

Permission

The library requires two permissions:

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

If you do not have permission to apply, this framework will check and apply at startup.

Launch 🚀 (Kotlin)

FilePickerManager
        .from(this@SampleActivity)
        .forResult(FilePickerManager.REQUEST_CODE)

Now that you have taken off 🛩️ ... ( there are really only two lines )

You only need to add .INSTANCE to use it:

FilePickerManager.INSTANCE
                .from(this)
                .forResult(FilePickerManager.REQUEST_CODE);

Receive Result

In onActivityResult() callback of the starting Activity or Fragment:

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, "You didn't choose anything~", Toast.LENGTH_SHORT).show()
            }
        }
    }
}

The result is a path list of the selected file (ArrayList<String>()).

proguard-rules(For pre v0.5.1)

-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>;
}

Starting with 0.5.2, we removed the coroutine library and implemented it using native threads, so there is no need to add proguard-rules.

Docs


Special Thanks To:

androidfilepicker's People

Contributors

dependabot-preview[bot] avatar rosuh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.