Giter VIP home page Giter VIP logo

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.

Android Arsenal

Using Maven

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

Or Using Gradle

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

<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. FolderChooser - Used to select single/multiple folders in storage (has some IO features)
  4. 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. FolderChooser

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();
      }
}
        
  • For Multiple Selection
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<Uri> selectedFiles  = data.getParcelableArrayListExtra(Constants.SELECTED_ITEMS);
      }
}
        

4. 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]

android-filebrowser-filepicker's People

Contributors

adityak368 avatar egonzalez-nabenik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-filebrowser-filepicker's Issues

Unable to find explicit activity class {in.example.com/com.aditya.filebrowser.FileBrowser}; have you declared this activity in your AndroidManifest.xml?

Fatal Exception: android.content.ActivityNotFoundException: Unable to find explicit activity class {in.transmr.daxfer/com.aditya.filebrowser.FileBrowser}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1777)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501)
at android.app.Activity.startActivityForResult(Activity.java:3745)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:767)
at android.app.Activity.startActivityForResult(Activity.java:3706)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:754)
at android.app.Activity.startActivity(Activity.java:4016)
at android.app.Activity.startActivity(Activity.java:3984)
at in.transmr.daxfer.activity.MainActivity.onNavigationItemSelected(MainActivity.java:1119)
at android.support.design.widget.NavigationView$1.onMenuItemSelected(NavigationView.java:170)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:840)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:991)
at android.support.design.internal.NavigationMenuPresenter$1.onClick(NavigationMenuPresenter.java:352)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

android.os.FileUriExposedException

Hi,
It seems for android api >= 24, app crashes when trying to share files.
Here is my stacktrace:
Fatal Exception: android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.company.app/files/Log/data_2020-03-09_09%3A31%3A27.csv exposed beyond app through ClipData.Item.getUri() at android.os.StrictMode.onFileUriExposed(StrictMode.java:1978) at android.net.Uri.checkFileUriExposed(Uri.java:2371) at android.content.ClipData.prepareToLeaveProcess(ClipData.java:963) at android.content.Intent.prepareToLeaveProcess(Intent.java:10216) at android.content.Intent.prepareToLeaveProcess(Intent.java:10222) at android.content.Intent.prepareToLeaveProcess(Intent.java:10201) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1667) at android.app.Activity.startActivityForResult(Activity.java:4586) at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676) at android.app.Activity.startActivityForResult(Activity.java:4544) at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:663) at android.app.Activity.startActivity(Activity.java:4905) at android.app.Activity.startActivity(Activity.java:4873) at com.aditya.filebrowser.fileoperations.FileIO.shareMultipleFiles(FileIO.java:253) at com.aditya.filebrowser.ToolbarActionMode.onActionItemClicked(ToolbarActionMode.java:80) at androidx.appcompat.app.AppCompatDelegateImpl$ActionModeCallbackWrapperV9.onActionItemClicked(AppCompatDelegateImpl.java:2452) at androidx.appcompat.view.StandaloneActionMode.onMenuItemSelected(StandaloneActionMode.java:141) at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:840) at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158) at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:991) at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:981) at androidx.appcompat.widget.ActionMenuView.invokeItem(ActionMenuView.java:625) at androidx.appcompat.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:151) at android.view.View.performClick(View.java:6614) at android.view.View.performClickInternal(View.java:6587) at android.view.View.access$3100(View.java:784) at android.view.View$PerformClick.run(View.java:26125) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6715) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)

java.lang.NullPointerException

When we click back button without selecting any file, it displays a toast with null pointer exception.
The message is :
"java.lang.NullPointerException: Attempt to
invoke virtual method 'java.util.ArrayList
android.content.Intent.getParcelableArra
yList Extra(java.lang.String) on a null object
reference"

Android 8

Please update for SDK Version 27, thanks!

After applying filter for displaying only specific files, it's still showing files without extensions

Hi @adityak368,

Great library :)

What am I trying to do?
I want to display only excel files

What is displaying right now?
No matters which filter you set, it always shows files that don't have any extentions

image

I have applied filters as per documentation in readme file

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

The back button is too cumbersome

First of all, I want to thank the author, because the View is convenient.
Issue as follows:
If I find file I need after looking for multi-level directory, I need to return to my application immediately rather than pressing the back button once every level,when I use the FileBrowser.
It will waste a lot of time.
I think you can add a new button which can return to the application or destory the FileBrowserActivity immediately.

open

hello and thank you for good lib.
i want to open audio file when FileBrowser lunched but when click on audio file close FileBrowser and no things !
what do i do ?

Not show any file and folder in android 10

the library working on my application before android 10, but after updating to android 10, the file browser doesn't show any folder or files!
Storage permission is granted but nothing is shown in the chooser!

"Show folder size" -> "Hide folder size"

"Show folder size" should be changed to "Hide folder size" after choosing this menu option and vice versa.

Please, provide a project with a sample usage of your library for all possible cases, because it seems only "Browse" use case is working as intended :(

I suppose a "Single Choice" use case should be arranged with radio buttons.

Fatal Exception: java.lang.ArrayIndexOutOfBoundsException

Unexpected crash in adapter. Please fix this asap

Fatal Exception: java.lang.ArrayIndexOutOfBoundsException: length=109; index=-1
at java.util.ArrayList.get(ArrayList.java:413)
at com.aditya.filebrowser.adapters.CustomAdapter.getItemAt(CustomAdapter.java:197)
at com.aditya.filebrowser.FileChooser$1.onItemClick(FileChooser.java:175)
at com.aditya.filebrowser.adapters.CustomAdapterItemClickListener.onInterceptTouchEvent(CustomAdapterItemClickListener.java:46)

at android.support.v7.widget.RecyclerView.dispatchOnItemTouch(RecyclerView.java:2658)
at android.support.v7.widget.RecyclerView.onTouchEvent(RecyclerView.java:2786)
at android.view.View.dispatchTouchEvent(View.java:10024)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2626)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2307)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:416)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1808)
at android.app.Activity.dispatchTouchEvent(Activity.java:3065)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:71)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:71)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:378)
at android.view.View.dispatchPointerEvent(View.java:10244)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4450)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4318)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3865)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3918)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3884)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4011)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3892)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4068)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3865)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3918)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3884)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3892)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3865)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6259)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6233)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6194)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6362)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:6236)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:891)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781)

exceeding dex limit

I got exeeding dex limit:

Error:Error converting bytecode to dex:
Cause: com.android.dex.DexIndexOverflowException: Cannot merge new index 66596 into a non-jumbo instruction!

Library crashes when user clicks on "Ext" button

Wanted to use it on my app, but library crashes when I press on "Ext" button. Log file is attached below.
Phone is Nexus 5X.

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getAbsolutePath()' on a null object reference
at com.aditya.filebrowser.FileChooser.updateUI(FileChooser.java:243)
at com.aditya.filebrowser.NavigationHelper.updateObservers(NavigationHelper.java:136)
at com.aditya.filebrowser.NavigationHelper.navigateToExternalStorage(NavigationHelper.java:58)
at com.aditya.filebrowser.listeners.TabChangeListener.handleTabChange(TabChangeListener.java:69)
at com.aditya.filebrowser.listeners.TabChangeListener.onTabSelected(TabChangeListener.java:52)
at com.roughike.bottombar.BottomBar.updateSelectedTab(BottomBar.java:949)
at com.roughike.bottombar.BottomBar.handleClick(BottomBar.java:926)
at com.roughike.bottombar.BottomBar.onClick(BottomBar.java:893)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

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.