项目作者: kalibrantas

项目描述 :
Lightweight Android File Chooser
高级语言: Java
项目地址: git://github.com/kalibrantas/kfilechooser.git
创建时间: 2018-05-08T20:29:47Z
项目社区:https://github.com/kalibrantas/kfilechooser

开源协议:

下载


kfilechooser

Lightweight Android File Chooser

Feature

  • File and folder chooser mode
  • File and folder name and extension filtering
  • Easy to use

Intall

Add jcenter repositories to your project gradle if not present, usually its automatically added by android studio.

In your application build.gradle dependencies add this line, for grandle <3.0 :

  1. compile 'kbrs.com.kfilechooser:kfilechooser:1.0'

for grandle >=3.0 :

  1. implementation 'kbrs.com.kfilechooser:kfilechooser:1.0'
  • Dont forget to add uses permission in android manifest to read external storage
  1. <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>

Usage

  • Minimal usage of this library
  1. KFileChooser.getInstance()
  2. .setRootDir(Environment.getExternalStorageDirectory())
  3. .setOnFileChooserResultListener(new KFileChooser.OnFileChooserResultListener() {
  4. @Override
  5. public void onResult(File fileResult) {
  6. if(fileResult!=null){
  7. //do your action here
  8. }
  9. }
  10. @Override
  11. public void onCancel(File lastChoosed) {
  12. }
  13. })
  14. .show(getSupportFragmentManager());
  • In your onResult method dont forget to check if the result file is null or not. Null File instance return if nothing file is choosed.

  • Full usage of this library:

    1. KFileChooser.getInstance()
    2. .setTitle("My File Chooser")
    3. .setRootDir(Environment.getExternalStorageDirectory())
    4. .setSelect(KFileFilter.MODE_SELECT_FILE)
    5. /* KFileFilter.MODE_SELECT_FILE || KFileFilter.MODE_SELECT_FOLDER || KFileFilter.MODE_SELECT_FOLDER_ONLY */
    6. .setExtension("pdf")
    7. /* .setExpression( yourRegularExpression ) */
    8. .setOnFileChooserResultListener(new KFileChooser.OnFileChooserResultListener() {
    9. @Override
    10. public void onResult(File fileResult) {
    11. if(fileResult!=null){
    12. //do your action here
    13. }
    14. }
    15. @Override
    16. public void onCancel(File lastChoosed) {
    17. }
    18. })
    19. .show(getSupportFragmentManager());

Compatibility

This library using DialogFragment and this project minimum target in android 15 or later