android-filepicker
来源:互联网 发布:淘宝买苹果手机靠谱吗 编辑:程序博客网 时间:2024/06/11 03:02
android-filepicker
Developed by
Angad Singh (@angads25)
Benchmark:
Where to Find:
Read all about internal classes and functions in the wiki.
Features
- Easy to Implement.
- No permissions required.
- Files, Directory Selection.
- Single or Multiple File selection.
Installation
- Library is also Available in MavenCentral, So just put this in your app dependencies to use it:
compile 'com.github.angads25:filepicker:1.0.6 '
Usage
FilePickerDialog
Start by creating an instance of
DialogProperties
.DialogProperties properties=new DialogProperties();
Now 'DialogProperties' has certain parameters.
Assign values to each Dialog Property using
DialogConfig
class.properties.selection_mode=DialogConfigs.SINGLE_MODE; properties.selection_type=DialogConfigs.FILE_SELECT; properties.root=new File(DialogConfigs.DEFAULT_DIR); properties.error_dir=new File(DialogConfigs.DEFAULT_DIR); properties.extensions=null;
Next create an instance of
FilePickerDialog
, and passContext
andDialogProperties
references as parameters. Optional: You can change the title of dialog. Default is current directory name.FilePickerDialog dialog = new FilePickerDialog(MainActivity.this,properties); dialog.setTitle("Select a File");
Next, Attach
DialogSelectionListener
toFilePickerDialog
as below,dialog.setDialogSelectionListener(new DialogSelectionListener() { @Override public void onSelectedFilePaths(String[] files) { //files is the array of the paths of files selected by the Application User. } });
An array of paths is returned whenever user press the
select
button`.Use
dialog.show()
method to show dialog.
NOTE:
Marshmallow and further requests for the permission on runtime. You should overrideonRequestPermissionsResult
in Activity/AppCompatActivity class and show the dialog only if permissions have been granted.
//Add this method to show Dialog when the required permission has been granted to the app. @Override public void onRequestPermissionsResult(int requestCode,@NonNull String permissions[],@NonNull int[] grantResults) { switch (requestCode) { case FilePickerDialog.EXTERNAL_READ_PERMISSION_GRANT: { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { if(dialog!=null) { //Show dialog if the read permission has been granted. dialog.show(); } } else { //Permission has not been granted. Notify the user. Toast.makeText(MainActivity.this,"Permission is Required for getting list of files",Toast.LENGTH_SHORT).show(); } } } }
That's It. You are good to go further.
FilePickerPreference
Start by declaring FilePickerPreference in your settings xml file as:
<com.github.angads25.filepicker.view.FilePickerPreference xmlns:app="http://schemas.android.com/apk/res-auto" android:key="your_preference_key" android:title="Pick a Directory" android:summary="Just a Summary" android:defaultValue="/sdcard:/mnt" app:titleText="Select Directories" app:error_dir="/mnt" app:root_dir="/sdcard" app:selection_mode="multi_mode" app:selection_type="dir_select" app:extensions="txt:pdf:"/>
Implement Preference.OnPreferenceChangeListener to class requiring selected values and
Override
onPreferenceChange(Preference, Object)
method. Check for preference key using Preference reference.@Override public boolean onPreferenceChange(Preference preference, Object o) { if(preference.getKey().equals("your_preference_key")) { ... } return false; }
Typecast
Object o
intoString
Object and usesplit(String)
function inString
class to get array of selected files.@Override public boolean onPreferenceChange(Preference preference, Object o) { if(preference.getKey().equals("your_preference_key")) { String value=(String)o; String arr[]=value.split(":"); ... ... } return false; }
That's It. You are good to move further.
Important:
defaultValue
,error_dir
,root_dir
must have valid directory/file paths.defaultValue
paths should end with ':'.defaultValue
can have multiple paths, there should be a ':' between two paths.extensions
must not have '.'.extensions
should end with ':' , also have ':' between two extensions. eg. /sdcard:/mnt:
Note:
FilePickerPreference stores selected directories/files as a String
. It delimits multiple files/directories using ':'char
.
Read more on implementation here.
Screenshot
Theme.Black
Theme.Holo
Theme.Holo.Light
Theme.Material
Theme.Device.Default
Performance
GPU Overdraw
GPU Rendering
- android-filepicker
- Android-FilePicker 选择照片
- Android-FilePicker 选择照片
- android开源库--FilePicker
- <win8>(五)实例讲解win8(XAML+C#)开发--------课程表:Appbar,FilePicker,启动页面(动画)
- Android
- android
- Android
- android
- android
- Android
- Android
- android
- android
- android
- Android
- Android
- android!!!
- Android实用代码片段整合
- 390. Elimination Game
- RSA private key file not found
- 接口回调
- .gitignore无效,不能过滤某些文件
- android-filepicker
- laravel框架怎么设置公共头和公共尾
- BZOJ 3832 [Poi2014]Rally
- icon-font 图标字体的使用
- maven Settings配置文件详解
- Linux-下载命令总结
- 未解决的bug,希望解决(计算行列式)
- stretchableImageWithLeftCapWidth
- [UIImage imageWithCVMat:(const cv::Mat&)cvMatt] 内存问题