获取视频列表
/**
- 获取本机视频列表
- @return
*/
public list getvideos() {
list videos = new arraylist();
cursor c = null;
try {
// string[] mediacolumns = { “_id”, “_data”, “_display_name”,
// “_size”, “date_modified”, “duration”, “resolution” };
c = mcontentresolver.query(mediastore.video.media.external_content_uri, null, null, null, mediastore.video.media.default_sort_order);
while (c.movetonext()) {
string path = c.getstring(c.getcolumnindexorthrow(mediastore.video.media.data));// 路径
if (!fileutils.isexists(path)) {
continue;
}
int id = c.getint(c.getcolumnindexorthrow(mediastore.video.media._id));// 视频的id
string name = c.getstring(c.getcolumnindexorthrow(mediastore.video.media.display_name)); // 视频名称
string resolution = c.getstring(c.getcolumnindexorthrow(mediastore.video.media.resolution)); //分辨率
long size = c.getlong(c.getcolumnindexorthrow(mediastore.video.media.size));// 大小
long duration = c.getlong(c.getcolumnindexorthrow(mediastore.video.media.duration));// 时长
long date = c.getlong(c.getcolumnindexorthrow(mediastore.video.media.date_modified));//修改时间
video video = new video(id, path, name, resolution, size, date, duration);
videos.add(video);
}
} catch (exception e) {
e.printstacktrace();
} finally {
if (c != null) {
c.close();
}
}
return videos;
}
其中,视频的bean类video代码为:
public class video {
private int id = 0;
private string path = null;
private string name = null;
private string resolution = null;// 分辨率
private long size = 0;
private long date = 0;
private long duration = 0;
public video(int id, string path, string name, string resolution, long size, long date, long duration) {
this.id = id;
this.path = path;
this.name = name;
this.resolution = resolution;
this.size = size;
this.date = date;
this.duration = duration;
}
… //此处省略setter和getter方法
}
通过本地视频id获取视频缩略图
// 获取视频缩略图
public bitmap getvideothumbnail(int id) {
bitmap bitmap = null;
bitmapfactory.options options = new bitmapfactory.options();
options.indither = false;
options.inpreferredconfig = bitmap.config.argb_8888;
bitmap = mediastore.video.thumbnails.getthumbnail(mcontentresolver, id, mediastore.images.thumbnails.micro_kind, options);
return bitmap;
}
上面获取视频列表的方法中,video对象中有一个属性是id,通过传入这个id可以获取到视频缩略图的bitmap对象。
获取本机所有图片文件夹
/**
- 得到图片文件夹集合
*/
public list getimagefolders() {
list folders = new arraylist();
// 扫描图片
cursor c = null;
try {
c = mcontentresolver.query(mediastore.images.media.external_content_uri, null,
mediastore.images.media.mime_type + "= ? or " + mediastore.images.media.mime_type + “= ?”,
new string[]{“image/jpeg”, “image/png”}, mediastore.images.media.date_modified);
list mdirs = new arraylist();//用于保存已经添加过的文件夹目录
while (c.movetonext()) {
string path = c.getstring(c.getcolumnindex(mediastore.images.media.data));// 路径
file parentfile = new file(path).getparentfile();
if (parentfile == null)
continue;
string dir = parentfile.getabsolutepath();
if (mdirs.contains(dir))//如果已经添加过
continue;
mdirs.add(dir);//添加到保存目录的集合中
imgfolderbean folderbean = new imgfolderbean();
folderbean.setdir(dir);
folderbean.setfistimgpath(path);
if (parentfile.list() == null)
continue;
int count = parentfile.list(new filenamefilter() {
@override
public boolean accept(file dir, string filename) {
if (filename.endswith(“.jpeg”) || filename.endswith(“.jpg”) || filename.endswith(“.png”)) {
return true;
}
return false;
}
}).length;
folderbean.setcount(count);
folders.add(folderbean);
}
} catch (exception e) {
e.printstacktrace();
} finally {
if (c != null) {
c.close();
}
}
return folders;
}
其中,图片文件夹的bean类imgfolderbean代码为:
public class imgfolderbean {
/*当前文件夹的路径/
private string dir;
/*第一张图片的路径,用于做文件夹的封面图片/
private string fistimgpath;
/*文件夹名/
private string name;
/*文件夹中图片的数量/
private int count;
public imgfolderbean(string dir, string fistimgpath, string name, int count) {
this.dir = dir;
this.fistimgpath = fistimgpath;
this.name = name;
this.count = count;
}
… //此处省略setter和getter方法
}
获取图片文件夹下的图片路径的集合
/**
- 通过图片文件夹的路径获取该目录下的图片
*/
public list getimglistbydir(string dir) {
arraylist imgpaths = new arraylist<>();
file directory = new file(dir);
if (directory == null || !directory.exists()) {
return imgpaths;
}
file[] files = directory.listfiles();
for (file file : files) {
string path = file.getabsolutepath();
if (fileutils.ispicfile(path)) {
imgpaths.add(path);
}
}
return imgpaths;
}
获取本机已安装应用列表
/**
- 获取已安装apk的列表
*/
public list getappinfos() {
arraylist appinfos = new arraylist();
//获取到包的管理者
packagemanager packagemanager = mcontext.getpackagemanager();
//获得所有的安装包
list installedpackages = packagemanager.getinstalledpackages(0);
//遍历每个安装包,获取对应的信息
for (packageinfo packageinfo : installedpackages) {
appinfo appinfo = new appinfo();
appinfo.setapplicationinfo(packageinfo.applicationinfo);
appinfo.setversioncode(packageinfo.versioncode);
//得到icon
drawable drawable = packageinfo.applicationinfo.loadicon(packagemanager);
appinfo.seticon(drawable);
//得到程序的名字
string apkname = packageinfo.applicationinfo.loadlabel(packagemanager).tostring();
appinfo.setapkname(apkname);
//得到程序的包名
string packagename = packageinfo.packagename;
appinfo.setapkpackagename(packagename);
//得到程序的资源文件夹
string sourcedir = packageinfo.applicationinfo.sourcedir;
file file = new file(sourcedir);
//得到apk的大小
long size = file.length();
appinfo.setapksize(size);
system.out.println(“---------------------------”);
system.out.println(“程序的名字:” + apkname);
system.out.println(“程序的包名:” + packagename);
system.out.println(“程序的大小:” + size);
//获取到安装应用程序的标记
int flags = packageinfo.applicationinfo.flags;
if ((flags & applicationinfo.flag_system) != 0) {
//表示系统app
appinfo.setisuserapp(false);
} else {
//表示用户app
appinfo.setisuserapp(true);
}
if ((flags & applicationinfo.flag_external_storage) != 0) {
//表示在sd卡
appinfo.setisrom(false);
} else {
//表示内存
appinfo.setisrom(true);
}
appinfos.add(appinfo);
}
return appinfos;
}
其中,安装包信息的bean类appinfo代码为:
public class appinfo {
private applicationinfo applicationinfo;
private int versioncode = 0;
/**
- 图片的icon
*/
private drawable icon;
/**
- 程序的名字
*/
private string apkname;
/**
- 程序大小
*/
private long apksize;
/**
- 表示到底是用户app还是系统app
- 如果表示为true 就是用户app
- 如果是false表示系统app
*/
private boolean isuserapp;
/**
- 放置的位置
*/
private boolean isrom;
/**
- 包名
*/
private string apkpackagename;
… //此处省略setter和getter方法
}
获取文档、压缩包、apk安装包等
/**
- 通过文件类型得到相应文件的集合
**/
public list getfilesbytype(int filetype) {
list files = new arraylist();
// 扫描files文件库
cursor c = null;
try {
c = mcontentresolver.query(mediastore.files.getcontenturi(“external”), new string[]{“_id”, “_data”, “_size”}, null, null, null);
int dataindex = c.getcolumnindex(mediastore.files.filecolumns.data);
int sizeindex = c.getcolumnindex(mediastore.files.filecolumns.size);
while (c.movetonext()) {
string path = c.getstring(dataindex);
if (fileutils.getfiletype(path) == filetype) {
if (!fileutils.isexists(path)) {
continue;
}
long size = c.getlong(sizeindex);
filebean filebean = new filebean(path, fileutils.getfileiconbypath(path));
files.add(filebean);
}
}
} catch (exception e) {
e.printstacktrace();
} finally {
if (c != null) {
c.close();
}
}
return files;
}
传入的filetype文件类型是在fileutils定义的文件类型声明:
/*文档类型/
public static final int type_doc = 0;
/*apk类型/
public static final int type_apk = 1;
/*压缩包类型/
public static final int type_zip = 2;
其中,fileutils根据文件路径获取文件类型的方法getfiletype(string path)为:
public static int getfiletype(string path) {
path = path.tolowercase();
if (path.endswith(“.doc”) || path.endswith(“.docx”) || path.endswith(“.xls”) || path.endswith(“.xlsx”)
|| path.endswith(“.ppt”) || path.endswith(“.pptx”)) {
return type_doc;
}else if (path.endswith(“.apk”)) {
return type_apk;
}else if (path.endswith(“.zip”) || path.endswith(“.rar”) || path.endswith(“.tar”) || path.endswith(“.gz”)) {
return type_zip;
}else{
return -1;
}
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、oppo等大厂,18年进入阿里一直到现在。
深知大多数android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加v获取:vip204888 (备注android)
最后
分享一份工作1到5年以上的android程序员架构进阶学习路线体系,希望能对那些还在从事android开发却还不知道如何去提升自己的,还处于迷茫的朋友!
-
阿里p7级android架构师技术脑图;查漏补缺,体系化深入学习提升
-
**全套体系化高级架构视频;**七大主流技术模块,视频+源码+笔记
有任何问题,欢迎广大网友一起来交流
笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新**
如果你觉得这些内容对你有帮助,可以添加v获取:vip204888 (备注android)
[外链图片转存中…(img-0l9dmj7a-1711923579069)]
最后
分享一份工作1到5年以上的android程序员架构进阶学习路线体系,希望能对那些还在从事android开发却还不知道如何去提升自己的,还处于迷茫的朋友!
-
阿里p7级android架构师技术脑图;查漏补缺,体系化深入学习提升
[外链图片转存中…(img-tspvufuj-1711923579069)]
-
**全套体系化高级架构视频;**七大主流技术模块,视频+源码+笔记
[外链图片转存中…(img-cbngtyst-1711923579070)]
有任何问题,欢迎广大网友一起来交流
发表评论