Android-FileBrowser-FilePicker


Source link: https://github.com/adityak368/Android-FileBrowser-FilePicker

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.7</version>
<type>pom</type> </dependency>

Or Using Gradle

compile 'com.adityak:browsemyfiles:1.7' 

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()

To load a particular directory instead of the normal root directory

Add the following in the intent

Intent i = new Intent(this, FileBrowser.class);
 //works for all 3 main classes (i.e FileBrowser, FileChooser, FileBrowserWithCustomHandler) i.putExtra(Constants.INITIAL_DIRECTORY, new File(Environment.getExternalStorageDirectory().getAbsolutePath(),"Movies").getAbsolutePath());

To list only the files with a particular extension

Add the following in the intent

Intent i = new Intent(this, FileBrowser.class);
 //works for all 3 main classes (i.e FileBrowser, FileChooser, FileBrowserWithCustomHandler) i.putExtra(Constants.ALLOWED_FILE_EXTENSIONS, "mkv;mp4;avi");

Use file extensions delimited by semicolon

Known Issues

Currently folder size is calculated using Java's Api getTotalSpace() which gives the size of the partition of the path which may not always give the desired result. To get the exact size, properties can be used which gives the exact result. If Exact size is to be known, then UI would lag as it would take some time to calculate size - Fix for this is postponed

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

Resources

This library provides an easy to use API for switching between fragments that share the same container. Implementing tabs, such as the ones Instagram has at the bottom of the layout, is a much simpler goal to achieve when using TabController.

Tabs can be switched by using either show/hide or attach/detach. You can even provide your own implementation of the way tabs are being shown.

WCViewPagerIndicators It is an android library that allows developers to have a viewpager with the attribute layoutheight = "wrapcontent", in addition to include in the bottom a page indicator (API 16 or higher)

Google Primer Intro Animation.

Eliminates need to create a static function to initialize a fragment and bind the arguments.

Jsonsurfer is dedicated in processing big and complicated json data with three major features.

FloatingActionButton menu library.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes