Android imitation WeChat release friend circle picture multi-selector implementation
Some time ago, due to the needs of the project, I made a function of multi-selection of pictures in WeChat circle of friends, which supports single / multiple selection of pictures. Support video, picture scanning
and video picture preview. And upload the function module to jitPack. Packaging process: Click here to view the packaging release process
Method 1: Use gitHub to download and import the module into your own project, there are examples of use on gitHub
Use method two: directly download and use
Step one, add the repository in the project's build.Gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step two: add dependencies
dependencies { implementation 'com.github.ytf12138:PictureSelector:v1.1' }
Call in code:
Get it with just one line of code:
PictureSelector.getInstance()
.setTitle("图片选择")//设置标题
.setMaxCount(9)//设置最大选择数量
.setShowImage(true)//是否显示图片,默认true
.setShowVideo(true)//是否显示视频,默认false
.setSelectType(false)//是否能同时选择图片和视频,默认false
.setShowCamera(false)//是否显示拍照item,默认false
.start(MainActivity.this, 1);//设置回调时 requestCode
Selection result reception:
In the callback method of Activity:
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == REQUEST_SELECTOR && resultCode == RESULT_OK) {
ArrayList<String> arrayList = data.getStringArrayListExtra(PictureSelector.SELECT_ITEM);
}
}
The selected image path is saved in arrayList