Coder Social home page Coder Social logo

android-filepicker's Introduction

FilePicker

Android Library to select files/directories from Device Storage.

Benchmark:

API

Where to Find:

Download Maven Central Android Arsenal

Features

  • Easy to Implement.
  • No permissions required.
  • Files, Directory Selection.
  • Single or Multiple File selection.

Installation

  • Library is also Available in MavenCentral, So just put this in your app dependencies:
    compile 'com.github.angads25:filepicker:1.0.2'

Usage

  1. Start by creating an instance of DialogProperties.

        DialogProperties properties=new DialogProperties();

    Now 'DialogProperties' has certain parameters.

Parameter Type Function
selection_mode int Selection Mode defines whether a single of multiple Files/Directories have to be selected.
selection_type int Selection Type defines whether a File/Directory or both of these has to be selected.
root File The Parent/Root Directory. List of Files are populated from here. Can be set to any readable directory.
extensions String[] An Array of String containing extensions, Files with only that will be shown. Others will be ignored.
  1. Assign values to each Dialog Property using DialogConfig class.

        properties.selection_mode=DialogConfigs.SINGLE_MODE;
        properties.selection_type=DialogConfigs.FILE_SELECT;
        properties.root=new File(DialogConfigs.DEFAULT_DIR);
        properties.extensions=null;

    Read more about DialogConfigs and other options from here.

  2. Next create an instance of FilePickerDialog, and pass Context and DialogProperties references as parameters.

        FilePickerDialog dialog = new FilePickerDialog(MainActivity.this,properties);
  3. Next, Attach DialogSelectionListener to FilePickerDialog as below,

        dialog.setDialogSelectionListener(new DialogSelectionListener() {
            @Override
            public void onSelectedFilePaths(String[] files) {
                //files is the array of the paths of files selected by the Application User.
            }
        });

    An array of paths is returned whenever user press the select button`.

  4. Use dialog.show() method to show dialog.

    That's It. You are good to go further.

NOTE:

Marshmallow and further requests for the permission during runtime. I would recommend to override onRequestPermissionsResult of Activity/AppCompatActivity class and show the dialog only if permissions have been granted.

        //Add this method to show Dialog when the required permission has been granted to the app.
        @Override
        public void onRequestPermissionsResult(int requestCode,@NonNull String permissions[],@NonNull int[] grantResults) {
            switch (requestCode) {
                case FilePickerDialog.EXTERNAL_READ_PERMISSION_GRANT: {
                    if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                        if(dialog!=null)
                        {   //Show dialog if the read permission has been granted.
                            dialog.show();
                        }
                    }
                    else {
                        //Permission has not been granted. Notify the user.
                        Toast.makeText(MainActivity.this,"Permission is Required for getting list of files",Toast.LENGTH_SHORT).show();
                    }
                }
            }
        }

Screenshots

Screenshot 1

Screenshot 2

Screenshot 3

Screenshot 4

android-filepicker's People

Watchers

 avatar  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.