android 选取图片file,Android-FilePicker 选择照片

况明贤
2023-12-01

As of now, It is only available in jCenter(), So just put this in your app dependencies:compile 'com.droidninja:filepicker:1.0.6'

Usage

Just include this in your onclick function:

For photopicker:FilePickerBuilder.getInstance().setMaxCount(5)

.setSelectedFiles(filePaths)

.setActivityTheme(R.style.AppTheme)

.pickPhoto(this);

For document picker:FilePickerBuilder.getInstance().setMaxCount(10)

.setSelectedFiles(filePaths)

.setActivityTheme(R.style.AppTheme)

.pickDocument(this);

After this, you will get list of file paths in activity result:@Override

public void onActivityResult(int requestCode, int resultCode, Intent data) {

switch (requestCode)

{

case FilePickerConst.REQUEST_CODE_PHOTO:

if(resultCode== Activity.RESULT_OK && data!=null)

{

photoPaths = new ArrayList<>();

photoPaths.addAll(data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_PHOTOS));

}

break;

case FilePickerConst.REQUEST_CODE_DOC:

if(resultCode== Activity.RESULT_OK && data!=null)

{

docPaths = new ArrayList<>();

docPaths.addAll(data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_DOCS));

}

break;

}

addThemToView(photoPaths,docPaths);

}

Credits

Inspired by PhotoPicker

 类似资料: