android 图片选择,可选择图片,视频,音频,文件,方便扩展
Posted brilliantzzk
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android 图片选择,可选择图片,视频,音频,文件,方便扩展相关的知识,希望对你有一定的参考价值。
androidFilePicker
android file picker ,you can choose image,video,file,etc..
Image selector library for Android. Support single choice、multi-choice、cropping image and preview image.
Quick start
1) Add Library module as a dependency in your build.gradle file.
or
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
allprojects
repositories
...
maven url 'https://jitpack.io'
Step 2. Add the dependency
dependencies
compile 'com.github.BrillantZhao:AndroidFilePicker:1.0.2'
2) Declare permission in your AndroidManifest.xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
3) 图片选择
int mode = selectMode.getCheckedRadioButtonId() == R.id.mode_multiple ? ImagePickActivity.MODE_MULTIPLE : ImagePickActivity.MODE_SINGLE;
boolean isShow = showCamera.getCheckedRadioButtonId() == R.id.camera_yes ? true : false;
boolean isPreview = enablePreview.getCheckedRadioButtonId() == R.id.preview_enable ? true : false;
boolean isCrop = enableCrop.getCheckedRadioButtonId() == R.id.crop_enable ? true : false;
ImagePickActivity.start(ImageActivity.this, maxSelectNum, mode, isShow, isPreview, isCrop, ImagePickActivity.REQUEST_IMAGE);
same this
/**
* 启动图片选择页面
*
* @param activity
* @param maxSelectNum 最大选择图片数量
* @param mode 单选or多选
* @param isShow 是否展示照相机
* @param enablePreview 是否允许预览
* @param enableCrop 是否允许裁剪
* @param requestCode 请求码
*/
public static void start(Activity activity, int maxSelectNum, int mode, boolean isShow,
boolean enablePreview, boolean enableCrop, int requestCode)
Intent intent = new Intent(activity, ImagePickActivity.class);
intent.putExtra(EXTRA_MAX_SELECT_NUM, maxSelectNum);
intent.putExtra(EXTRA_SELECT_MODE, mode);
intent.putExtra(EXTRA_SHOW_CAMERA, isShow);
intent.putExtra(EXTRA_ENABLE_PREVIEW, enablePreview);
intent.putExtra(EXTRA_ENABLE_CROP, enableCrop);
activity.startActivityForResult(intent, requestCode);
Receive result in your onActivityResult Method
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
if (resultCode == RESULT_OK && requestCode == ImagePickActivity.REQUEST_IMAGE)
ArrayList<ImageFile> images = data.getParcelableArrayListExtra(Constant.RESULT_PICK_IMAGE);
// do something ...
4) 视频选择
boolean isShow = showCamera.getCheckedRadioButtonId() == R.id.camera_yes ? true : false;
VideoPickActivity.start(VideoActivity.this, maxSelectNum, isShow,VideoPickActivity.REQUEST_VIDEO);
same this
/**
* 启动视频选择
*
* @param activity
* @param maxSelectNum 最大选择数量
* @param isShow 是否展示摄像头
* @param requestCode 请求码
*/
public static void start(Activity activity, int maxSelectNum, boolean isShow, int requestCode)
Intent intent = new Intent(activity, VideoPickActivity.class);
intent.putExtra(EXTRA_MAX_SELECT_NUM, maxSelectNum);
intent.putExtra(EXTRA_SHOW_CAMERA, isShow);
activity.startActivityForResult(intent, requestCode);
Receive result in your onActivityResult Method
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
if (resultCode == RESULT_OK && requestCode == VideoPickActivity.REQUEST_VIDEO)
ArrayList<VideoFile> videoFiles = data.getParcelableArrayListExtra(Constant.RESULT_PICK_VIDEO);
// do something...
5) 文件选择
String[] mSuffix = "txt";
NormalFilePickActivity.start(FileActivity.this, maxSelectNum, mSuffix, NormalFilePickActivity.REQUEST_FILE);
same this
/**
* 启动文件选择
*
* @param activity
* @param maxSelectNum 最大选择数量
* @param mSuffix 文件格式集合
* @param requestCode 请求码
*/
public static void start(Activity activity, int maxSelectNum, String[] mSuffix, int requestCode)
Intent intent = new Intent(activity, NormalFilePickActivity.class);
intent.putExtra(EXTRA_MAX_SELECT_NUM, maxSelectNum);
intent.putExtra(EXTRA_STUFFIX, mSuffix);
activity.startActivityForResult(intent, requestCode);
Receive result in your onActivityResult Method
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
if (resultCode == RESULT_OK && requestCode == NormalFilePickActivity.REQUEST_FILE)
ArrayList<NormalFile> normalFiles = data.getParcelableArrayListExtra(Constant.RESULT_PICK_FILE);
// do something...
5) 音频选择
boolean isNeedRecorder = showCamera.getCheckedRadioButtonId() == R.id.camera_yes ? true : false;
AudioPickActivity.start(AudioActivity.this, maxSelectNum, isNeedRecorder, AudioPickActivity.REQUEST_AUDIO);
same this
/**
* 启动录音选择
*
* @param activity
* @param maxSelectNum 最大选择数量
* @param isNeedRecorder 是否需要录音
* @param requestCode 请求码
*/
public static void start(Activity activity, int maxSelectNum, boolean isNeedRecorder, int requestCode)
Intent intent = new Intent(activity, AudioPickActivity.class);
intent.putExtra(EXTRA_MAX_SELECT_NUM, maxSelectNum);
intent.putExtra(IS_NEED_RECORDER, isNeedRecorder);
activity.startActivityForResult(intent, requestCode);
Receive result in your onActivityResult Method
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
if (resultCode == RESULT_OK && requestCode == AudioPickActivity.REQUEST_AUDIO)
ArrayList<AudioFile> audioFiles = data.getParcelableArrayListExtra(Constant.RESULT_PICK_VIDEO);
// do something...
用到的第三方库
Glide
compile ‘com.github.bumptech.glide:glide:3.7.0’
PhotoView
compile ‘com.bm.photoview:library:1.4.1’
//===
compile ‘pub.devrel:easypermissions:0.2.1’
simplecropview
compile ‘com.isseiaoki:simplecropview:1.0.13’
项目地址(欢迎fork):https://github.com/BrillantZhao/AndroidFilePicker
以上是关于android 图片选择,可选择图片,视频,音频,文件,方便扩展的主要内容,如果未能解决你的问题,请参考以下文章
Uniapp 图片选择插件(支持视频音频) Ba-MediaPicker
Uniapp 图片选择插件(支持视频音频) Ba-MediaPicker
uniapp文件管理 文件列表 获取媒体文件 图片视频音频文档压缩包文件并实现可删除文件 图片文件列表 视频文件列表 音频文件列表 获取内存卡图片视频音频pdf xlxs docx txt
Unity 浏览选择指定格式文件(可设置格式:图片视频音频等等,自己设置)浏览选择文件夹打开指定文件夹——以上功能都会返回路径