android打开图片、视频、文件选择器

本文详细介绍了在Android应用中如何实现图片、视频和文件选择器的功能,包括使用Intent调用系统选择器,自定义选择器的UI设计以及处理选择结果的方法,帮助开发者提升用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.首先在build.gradle中加入
implementation 'com.github.LuckSiege.PictureSelector:picture_library:v2.2.3'
2.
/**
 * 选择多张图片
 */
private void selectmanyPics(int maxNum) {
    PictureSelector.create(MainActivity.this)
            .openGallery(PictureMimeType.ofImage())
            .maxSelectNum(maxNum)
            .selectionMedia(selectList)
            .forResult(REQUEST_UPLOAD_MANYFILE);
}

/**
 * 选择视频
 */
private void selectVideo() {
    PictureSelector.create(MainActivity.this)
            .openGallery(PictureMimeType.ofVideo())
            .maxSelectNum(1)
            .selectionMedia(selectList)
            .forResult(REQUEST_UPLOAD_FILE);
}

 

/**
 * 选择文件
 */
private void openFileManager() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");//设置类型,我这里是任意类型,任意后缀的可以这样写。
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(intent, REQUEST_UPLOAD_FILE);
}
/**
 * 选择一张图片-带剪切
 */
private void selectgOneCutPic() {
    PictureSelector.create(MainActivity.this)
            .openGallery(PictureMimeType.ofImage())
            .imageSpanCount(3)
            .maxSelectNum(1)
            .selectionMode(PictureConfig.SINGLE)
            .previewImage(true)
            .previewVideo(false)
            .enableCrop(true)
            .freeStyleCropEnabled(false)
            .circleDimmedLayer(false)
            .showCropFrame(true)// 是否显示裁剪矩形边框 圆形裁剪时建议设为false   true or false
            .isCamera(true)
            .isZoomAnim(true)
            .showCropFrame(true)// 是否显示裁剪矩形边框 圆形裁剪时建议设为false   true or false
            .showCropGrid(false)
            .cropWH(600, 600)
            .withAspectRatio(1, 1)
            .selectionMedia(selectList)
            .minimumCompressSize(100)
            .isDragFrame(true)
            .forResult(PictureConfig.CHOOSE_REQUEST);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值