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.
android 图片选择,可选择图片,视频,音频,文件,方便扩展
android 图片选择,可选择图片,视频,音频,文件,方便扩展
android 图片选择,可选择图片,视频,音频,文件,方便扩展

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

上一篇:《Python金融大数据分析》一第5章 数据可视化


下一篇:工信部朱宏任:2014年中小企业信息化4大重点