|
2 | 2 |
|
3 | 3 | A FileBrowser / FileChooser for Android that you can integrate to your app to browse/select files from internal/external storage. |
4 | 4 |
|
5 | | -It easily integrates with your app's color scheme. |
| 5 | +<img src="https://cloud.githubusercontent.com/assets/19688735/25305189/670232ec-2794-11e7-819f-b92f487b3075.png" width="300"> <img src="https://cloud.githubusercontent.com/assets/19688735/25305190/670328a0-2794-11e7-86ac-62b69af7b577.png" width="300"> |
| 6 | +<img src="https://cloud.githubusercontent.com/assets/19688735/25305188/6701de1e-2794-11e7-981f-7d6d0124b2b2.png" width="300"> <img src="https://cloud.githubusercontent.com/assets/19688735/25305187/6701b74a-2794-11e7-8057-c5677db858b0.png" width="300"> |
| 7 | +<img src="https://cloud.githubusercontent.com/assets/19688735/25305186/6701b33a-2794-11e7-8c58-d5da64e40768.png" width="300"> <img src="https://cloud.githubusercontent.com/assets/19688735/25305191/67038f8e-2794-11e7-8777-4bb0db870c31.png" width="300"> |
| 8 | +<img src="https://cloud.githubusercontent.com/assets/19688735/25305192/6730cec2-2794-11e7-8ab0-9b696822520f.png" width="300"> <img src="https://cloud.githubusercontent.com/assets/19688735/25305193/6733e6fc-2794-11e7-852d-66fe162655d2.png" width="300"> |
| 9 | + |
| 10 | +It easily integrates with your app's color scheme. You can change the color scheme using |
| 11 | + |
| 12 | +``` xml |
| 13 | +<item name="colorPrimary">@color/colorPrimary</item> |
| 14 | +<item name="colorPrimaryDark">@color/colorPrimaryDark</item> |
| 15 | +<item name="colorAccent">@color/colorAccent</item> |
| 16 | +<item name="android:actionModeBackground">@color/actionModeToolbar</item> |
| 17 | +<item name="windowActionModeOverlay">true</item> |
| 18 | +``` |
6 | 19 |
|
7 | 20 | There are 3 main classes to use the library. |
8 | 21 |
|
9 | | -1. FileBrowser |
10 | | -2. FileChooser |
11 | | -3. FileBrowserWithCustomHandler |
| 22 | +1. FileBrowser - USed to just Browse files in storage (has all file IO features) |
| 23 | +2. FileChooser - Used to select single/multiple files in storage (has some IO features) |
| 24 | +3. FileBrowserWithCustomHandler - Used to run custom code when files are selected (has all IO features) |
| 25 | + |
| 26 | +# 1. FileBrowser |
| 27 | +Use following Intent to start the FileBrowser |
| 28 | + |
| 29 | +``` java |
| 30 | +Intent i4 = new Intent(getApplicationContext(), FileBrowser.class); |
| 31 | +startActivity(i4); |
| 32 | +``` |
| 33 | + |
| 34 | +# 2. FileChooser |
| 35 | + |
| 36 | +Use following Intent to start the FileChooser |
| 37 | + - For Single Selection |
| 38 | + |
| 39 | +``` java |
| 40 | +Intent i2 = new Intent(getApplicationContext(), FileChooser.class); |
| 41 | +i2.putExtra(Constants.SELECTION_MODE,Constants.SELECTION_MODES.SINGLE_SELECTION.ordinal()); |
| 42 | +startActivityForResult(i2,PICK_CONTACT_REQUEST); |
| 43 | +``` |
| 44 | + |
| 45 | + |
| 46 | +To get the selected file, In your calling activity's onActivityResult method, use the following |
| 47 | + |
| 48 | +```java |
| 49 | + |
| 50 | +if (requestCode == PICK_CONTACT_REQUEST && data!=null) { |
| 51 | + if (resultCode == RESULT_OK) { |
| 52 | + Uri file = data.getData(); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +``` |
| 57 | + |
| 58 | + |
| 59 | + - For Multiple Selection |
| 60 | +``` java |
| 61 | +Intent i2 = new Intent(getApplicationContext(), FileChooser.class); |
| 62 | +i2.putExtra(Constants.SELECTION_MODE,Constants.SELECTION_MODES.MULTIPLE_SELECTION.ordinal()); |
| 63 | +startActivityForResult(i2,PICK_CONTACT_REQUEST); |
| 64 | +``` |
| 65 | + |
| 66 | +To get the selected file, In your calling activity's onActivityResult method, use the following |
| 67 | + |
| 68 | +```java |
| 69 | + |
| 70 | +if (requestCode == PICK_CONTACT_REQUEST && data!=null) { |
| 71 | + if (resultCode == RESULT_OK) { |
| 72 | + ArrayList<Uri> selectedFiles = data.getParcelableArrayListExtra(Constants.SELECTED_ITEMS); |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +``` |
| 77 | + |
| 78 | +# 3. FileBrowserWithCustomHandler |
| 79 | + |
| 80 | +Register a Broadcast receiver and handle the onReceive method like below |
| 81 | + |
| 82 | +```java |
| 83 | + |
| 84 | +public class FileSelectedBroadCastReceiver extends BroadcastReceiver { |
| 85 | + @Override |
| 86 | + public void onReceive(Context context, Intent intent) { |
| 87 | + Uri filePath = intent.getParcelableExtra(com.aditya.filebrowser.Constants.BROADCAST_SELECTED_FILE); |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +``` |
| 92 | + |
| 93 | +If you also need some other parameters to be sent with the broadcast use the following when creating the activity |
| 94 | +``` java |
| 95 | + |
| 96 | +Intent i = new Intent(mContext, FileBrowserWithCustomHandler.class); |
| 97 | +Bundle ib = new Bundle(); |
| 98 | +//add extras |
| 99 | +i.putExtras(ib); |
| 100 | +startActivity(i); |
| 101 | + |
| 102 | +``` |
| 103 | +and in the broadcast receiver use the following to get the extras |
| 104 | + |
| 105 | +``` java |
| 106 | +Bundle b = intent.getExtras() |
| 107 | +``` |
| 108 | + |
12 | 109 |
|
13 | 110 |
|
14 | | -Use Intent to start the FileBrowser |
|
0 commit comments