A FileBrowser / FileChooser / FolderChooser for Android that you can integrate to your app to browse/select files from internal/external storage
A FileBrowser / FileChooser for Android that you can integrate to your app to browse/select files from internal/external storage.
com.adityak browsemyfiles 1.9 pom
compile 'com.adityak:browsemyfiles:1.9'
It easily integrates with your app's color scheme. You can change the color scheme using the following in your styles.xml
@color/colorPrimary @color/colorPrimaryDark @color/colorAccent @color/actionModeToolbar
There are 3 main classes to use the library.
Use following Intent to start the FileBrowser
Intent i4 = new Intent(getApplicationContext(), FileBrowser.class); startActivity(i4);
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(); } }
java 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 selectedFiles = data.getParcelableArrayListExtra(Constants.SELECTED_ITEMS); } }
Use following Intent to start the FolderChooser - For Single Selection
Intent i2 = new Intent(getApplicationContext(), FolderChooser.class); i2.putExtra(Constants.SELECTION_MODE, Constants.SELECTION_MODES.SINGLE_SELECTION.ordinal()); startActivityForResult(i2, PICK_FOLDER_REQUEST);
To get the selected folder, In your calling activity's onActivityResult method, use the following
if (requestCode == PICK_FOLDER_REQUEST && data!=null) { if (resultCode == RESULT_OK) { Uri file = data.getData(); } }
java Intent i2 = new Intent(getApplicationContext(), FolderChooser.class); i2.putExtra(Constants.SELECTION_MODE, Constants.SELECTION_MODES.MULTIPLE_SELECTION.ordinal()); startActivityForResult(i2, PICK_FOLDER_REQUEST);
To get the selected file, In your calling activity's onActivityResult method, use the following
if (requestCode == PICK_FOLDER_REQUEST && data!=null) { if (resultCode == RESULT_OK) { ArrayList selectedFiles = data.getParcelableArrayListExtra(Constants.SELECTED_ITEMS); } }
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
If you also need some other parameters to be sent with the broadcast use the following when creating the activity ``` java
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``` java Bundle b = intent.getExtras()
Add the following in the intent
java 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());
Add the following in the intent
java 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
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]