Giter Site home page Giter Site logo

msoftware / android-filebrowser-filepicker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adityak368/android-filebrowser-filepicker

0.0 2.0 0.0 365 KB

A FileBrowser / FileChooser for Android that you can integrate to your app to browse/select files from internal/external storage

License: MIT License

Java 100.00%

android-filebrowser-filepicker's Introduction

FileBrowser

A FileBrowser / FileChooser for Android that you can integrate to your app to browse/select files from internal/external storage.

Using Maven

<dependency>
  <groupId>com.adityak</groupId>
  <artifactId>browsemyfiles</artifactId>
  <version>1.2</version>
  <type>pom</type>
</dependency>

In build.gradle

compile 'com.adityak:browsemyfiles:1.2'

It easily integrates with your app's color scheme. You can change the color scheme using the following in your styles.xml

<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:actionModeBackground">@color/actionModeToolbar</item>

There are 3 main classes to use the library.

  1. FileBrowser - Used to just Browse files in storage (has all file IO features)
  2. FileChooser - Used to select single/multiple files in storage (has some IO features)
  3. FileBrowserWithCustomHandler - Used to run custom code when files are selected (has all IO features)

1. FileBrowser

Use following Intent to start the FileBrowser

Intent i4 = new Intent(getApplicationContext(), FileBrowser.class);
startActivity(i4);

2. FileChooser

Use following Intent to start the FileChooser

  • For Single Selection
Intent i2 = new Intent(getApplicationContext(), FileChooser.class);
i2.putExtra(Constants.SELECTION_MODE,Constants.SELECTION_MODES.SINGLE_SELECTION.ordinal());
startActivityForResult(i2,PICK_FILE_REQUEST);

To get the selected file, In your calling activity's onActivityResult method, use the following

if (requestCode == PICK_FILE_REQUEST && data!=null) {
      if (resultCode == RESULT_OK) {
          Uri file = data.getData();
      }
}
        
  • For Multiple Selection
Intent i2 = new Intent(getApplicationContext(), FileChooser.class);
i2.putExtra(Constants.SELECTION_MODE,Constants.SELECTION_MODES.MULTIPLE_SELECTION.ordinal());
startActivityForResult(i2,PICK_FILE_REQUEST);

To get the selected file, In your calling activity's onActivityResult method, use the following

if (requestCode == PICK_FILE_REQUEST && data!=null) {
      if (resultCode == RESULT_OK) {
          ArrayList<Uri> selectedFiles  = data.getParcelableArrayListExtra(Constants.SELECTED_ITEMS);
      }
}
        

3. FileBrowserWithCustomHandler

Register a Broadcast receiver and handle the onReceive method like below

public class FileSelectedBroadCastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
         Uri filePath = intent.getParcelableExtra(com.aditya.filebrowser.Constants.BROADCAST_SELECTED_FILE);
    }
}

Register the receiver like the following snippet

        <receiver android:name=".FileSelectedBroadCastReceiver"
            android:exported="false"
            android:enabled="true">
            <intent-filter>
                <action android:name="com.adityak.filebrowser.FILE_SELECTED_BROADCAST" />
            </intent-filter>
        </receiver>
        

If you also need some other parameters to be sent with the broadcast use the following when creating the activity

Intent i = new Intent(mContext, FileBrowserWithCustomHandler.class);
Bundle ib = new Bundle();
//add extras
i.putExtras(ib);
startActivity(i);

and in the broadcast receiver use the following to get the extras

Bundle b = intent.getExtras()

If you have any questions/queries/Bugs/Hugs please mail @ [email protected]

android-filebrowser-filepicker's People

Contributors

adityak368 avatar

Watchers

Michael jentsch 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.