MCPcopy Index your code
hub / github.com/adityak368/Android-FileBrowser-FilePicker

github.com/adityak368/Android-FileBrowser-FilePicker @1.9

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.9 ↗ · + Follow
232 symbols 614 edges 27 files 20 documented · 9%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

FileBrowser

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

Android Arsenal

Using Maven

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

Or Using Gradle

compile 'com.adityak:browsemyfiles:1.8'

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 @ adityak368@gmail.com

Extension points exported contracts — how you extend this code

OnFileChangedListener (Interface)
Created by Aditya on 4/18/2017. [8 implementers]
filebrowser/src/main/java/com/aditya/filebrowser/listeners/OnFileChangedListener.java
IContextSwitcher (Interface)
Created by Aditya on 4/18/2017. [8 implementers]
filebrowser/src/main/java/com/aditya/filebrowser/interfaces/IContextSwitcher.java
IFuncPtr (Interface)
Created by Aditya on 4/15/2017. [3 implementers]
filebrowser/src/main/java/com/aditya/filebrowser/interfaces/IFuncPtr.java
OnItemClickListener (Interface)
(no doc) [4 implementers]
filebrowser/src/main/java/com/aditya/filebrowser/adapters/CustomAdapterItemClickListener.java
ITrackSelection (Interface)
Created by Aditya on 4/15/2017. [2 implementers]
filebrowser/src/main/java/com/aditya/filebrowser/interfaces/ITrackSelection.java

Core symbols most depended-on inside this repo

getFile
called by 36
filebrowser/src/main/java/com/aditya/filebrowser/models/FileItem.java
ShowToast
called by 16
filebrowser/src/main/java/com/aditya/filebrowser/utils/UIUtils.java
getCurrentDirectory
called by 14
filebrowser/src/main/java/com/aditya/filebrowser/NavigationHelper.java
getInstance
called by 10
filebrowser/src/main/java/com/aditya/filebrowser/fileoperations/Operations.java
getChoiceMode
called by 10
filebrowser/src/main/java/com/aditya/filebrowser/adapters/CustomAdapter.java
triggerFileChanged
called by 9
filebrowser/src/main/java/com/aditya/filebrowser/NavigationHelper.java
changeDirectory
called by 8
filebrowser/src/main/java/com/aditya/filebrowser/NavigationHelper.java
getFilesItemsInCurrentDirectory
called by 8
filebrowser/src/main/java/com/aditya/filebrowser/NavigationHelper.java

Shape

Method 195
Class 26
Enum 6
Interface 5

Languages

Java100%

Modules by API surface

filebrowser/src/main/java/com/aditya/filebrowser/adapters/CustomAdapter.java20 symbols
filebrowser/src/main/java/com/aditya/filebrowser/FileBrowserWithCustomHandler.java18 symbols
filebrowser/src/main/java/com/aditya/filebrowser/FileBrowser.java18 symbols
filebrowser/src/main/java/com/aditya/filebrowser/FolderChooser.java17 symbols
filebrowser/src/main/java/com/aditya/filebrowser/FileChooser.java17 symbols
filebrowser/src/main/java/com/aditya/filebrowser/fileoperations/FileIO.java14 symbols
filebrowser/src/main/java/com/aditya/filebrowser/fileoperations/Operations.java13 symbols
filebrowser/src/main/java/com/aditya/filebrowser/listeners/TabChangeListener.java12 symbols
filebrowser/src/main/java/com/aditya/filebrowser/adapters/CustomAdapterItemClickListener.java12 symbols
filebrowser/src/main/java/com/aditya/filebrowser/NavigationHelper.java11 symbols
filebrowser/src/main/java/com/aditya/filebrowser/fileoperations/FileNavigator.java9 symbols
filebrowser/src/main/java/com/aditya/filebrowser/utils/UIUtils.java8 symbols

For agents

$ claude mcp add Android-FileBrowser-FilePicker \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact