android 图片文件选择文件,GitHub - ZJYZJY/FilePicker: Android文件、图片选择器,可按文件夹查找,文件类型查找,支持自定义相机,将原项目升级为AndroidX版...

该博客介绍了如何将Android项目升级到AndroidX,并实现一个文件选择器,允许用户通过文件浏览器选择指定后缀名的文件。选择器支持按类别查找文件、图片和视频选择,同时提供自定义主题和限制最大选择数量等功能。在onActivityResult中可获取选中文件的数据。此外,还提到了移除AndPermission依赖并支持多种图片加载框架的优化。

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

介绍

将原项目升级为AndroidX版本,并适配Andeoid Q

可在文件浏览器中选择指定后缀名文件

可通过扫描全盘的方式,选择指定后缀名的文件

类似微信图片选择器选择图片或视频

图片选择页面可以自定义主题

支持Activity、Fragment

Example

1082a108807070f6919502da2c5da173.png9a28eca583be7d1dd943c383b007828f.pnga0ecaafb00626061d4d8fde45a77ae07.png

d243e71d5198802a7edc88b60011c8cd.png4c68a9ea6cf1567aa2c732b5f2d71754.png7257e65428dab02f079f6f5c254b6045.png

可下载APK直接体验

用法

implementation project(':filepicker')

一、 在文件浏览器中选择指定文件

FilePicker.from(this)

.chooseForBrowser()

.setMaxCount(2)

.setFileTypes("png", "doc","apk", "mp3", "gif", "txt", "mp4", "zip")

.requestCode(REQUEST_CODE_CHOOSE)

.start();

二、 分类查找指定后缀名文件

FilePicker

.from(this)

.chooseForMimeType()

.setMaxCount(10)

.setFileTypes("png", "doc","apk", "mp3", "gif", "txt", "mp4", "zip")

.requestCode(REQUEST_CODE_CHOOSE)

.start();

三、 在图片选择器中选择图片或视频

FilePicker

.from(this)

.chooseMedia()

.enabledCapture(true)

.setTheme(R.style.FilePicker_Dracula)

.requestCode(REQUEST_CODE_CHOOSE)

.start();

四、 接收返回的文件数据,在 ++onActivityResult++ 方法中获取。选中文件以链表方式返回, ++EssFile++ 类为载体

@Override

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

super.onActivityResult(requestCode, resultCode, data);

if (resultCode != RESULT_OK) {

return;

}

if (requestCode == REQUEST_CODE_CHOOSE) {

ArrayList essFileList = data.getParcelableArrayListExtra(Const.EXTRA_RESULT_SELECTION);

StringBuilder builder = new StringBuilder();

for (EssFile file :

essFileList) {

builder.append(file.getMimeType()).append(" | ").append(file.getName()).append("\n\n");

}

textView.setText(builder.toString());

}

}

属性列表

名称

描述

默认值

FileTypes

需要显示的文件类型

SortType

排序类型

按名字排序 BY_NAME_ASC

isSingle

是否单选

false

maxCount

最大可选中数量

10

request_code

请求码

onlyShowImages

是否仅显示图片(仅当其实chooseMedia时有效)

false

onlyShowVideos

是否仅显示视频(仅当其实chooseMedia时有效)

false

enabledCapture

chooseMedia时是否显示照相机

false

placeHolder

图片的PlaceHolder

png_holder

themeId

主题ID

R.Style.FilePicker_Elec

自定义主题

@color/elec_primary

@color/elec_primary_dark

@style/Toolbar.elec

@color/elec_album_dropdown_title_text

@color/elec_album_dropdown_count_text

@android:color/white

@color/elec_album_dropdown_thumbnail_placeholder

@drawable/ic_empty_elec

@color/elec_album_empty_view

@color/elec_item_placeholder

@color/elec_item_checkCircle_backgroundColor

@color/elec_item_checkCircle_borderColor

@color/elec_page_bg

@color/elec_bottom_toolbar_bg

@color/elec_bottom_toolbar_preview

@color/elec_bottom_toolbar_apply

@color/elec_preview_bottom_toolbar_back_text

@color/elec_preview_bottom_toolbar_apply

@style/Popup.elec

@color/elec_capture

Feature TODO

根据文件类型打开/预览文件

预览图片界面

压缩图片

裁剪图片

自定义相机拍照

去掉AndPermission依赖,用原生代码申请权限

增加多种图片加载框架支持

文件浏览器支持自定义主题

分类选择文件界面支持自定义主题

THANKS

LICENSE

MIT License

Copyright (c) 2018

Permission is hereby granted, free of charge, to any person obtaining a copy

of this software and associated documentation files (the "Software"), to deal

in the Software without restriction, including without limitation the rights

to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

copies of the Software, and to permit persons to whom the Software is

furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all

copies or substantial portions of the Software.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值