android browser控件,Android-FileBrowser-FilePicker一个Android文件浏览和选择控件

FileBrowser

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

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f416e64726f6964253230417273656e616c2d416e64726f69642d2d46696c6542726f777365722d2d46696c655069636b65722d627269676874677265656e2e7376673f7374796c653d666c6174

Using Maven

com.adityak

browsemyfiles

1.9

pom

Or Using Gradle

compile 'com.adityak:browsemyfiles:1.9'

c7cdf27aa45834562a06a0eb11933bce.pngea8c233da254c75f89fad3f72c9902c5.png2237ed10f18b5e618798285a2166229f.png51738afc328cc27674a222e0dbdc74f6.png3ce28b711c29e37a697b0ae728c764c1.png524fcdf13e80edb44838e69c241f3fff.pngcebebbb31ed30a60941d001ace1895ab.pngdf55ea11bb6798a3a662feb317ecb494.png

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.

FileBrowser - Used to just Browse files in storage (has all file IO features)

FileChooser - Used to select single/multiple files in storage (has some IO features)

FolderChooser - Used to select single/multiple folders in storage (has some IO features)

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

android:exported="false"

android:enabled="true">

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值