獲取視頻列表
/**
- 獲取本機視頻列表
- @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();//用于保存已經(jīng)添加過的文件夾目錄
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))//如果已經(jīng)添加過
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 {
/*當(dāng)前文件夾的路徑/
private String dir;
/*第一張圖片的路徑,用于做文件夾的封面圖片/
private String fistImgPath;
/*文件夾名/
private String name;
/*文件夾中圖片的數(shù)量/
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;
}
獲取本機已安裝應(yīng)用列表
/**
- 獲取已安裝apk的列表
*/
public List getAppInfos() {
ArrayList appInfos = new ArrayList();
//獲取到包的管理者
PackageManager packageManager = mContext.getPackageManager();
//獲得所有的安裝包
List installedPackages = packageManager.getInstalledPackages(0);
//遍歷每個安裝包,獲取對應(yīng)的信息
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);
//獲取到安裝應(yīng)用程序的標(biāo)記
int flags = packageInfo.applicationInfo.flags;
if ((flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
//表示系統(tǒng)app
appInfo.setIsUserApp(false);
} else {
//表示用戶app
appInfo.setIsUserApp(true);
}
if ((flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
//表示在sd卡
appInfo.setIsRom(false);
} else {
//表示內(nèi)存
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還是系統(tǒng)app
- 如果表示為true 就是用戶app
- 如果是false表示系統(tǒng)app
*/
private boolean isUserApp;
/**
- 放置的位置
*/
private boolean isRom;
/**
- 包名
*/
private String apkPackageName;
… //此處省略setter和getter方法
}
獲取文檔、壓縮包、apk安裝包等
自我介紹一下,小編13年上海交大畢業(yè),曾經(jīng)在小公司待過,也去過華為、OPPO等大廠,18年進入阿里一直到現(xiàn)在。
深知大多數(shù)初中級安卓工程師,想要提升技能,往往是自己摸索成長,但自己不成體系的自學(xué)效果低效又漫長,而且極易碰到天花板技術(shù)停滯不前!
因此收集整理了一份《2024年最新Android移動開發(fā)全套學(xué)習(xí)資料》送給大家,初衷也很簡單,就是希望能夠幫助到想自學(xué)提升又不知道該從何學(xué)起的朋友,同時減輕大家的負擔(dān)。
由于文件比較大,這里只是將部分目錄截圖出來,每個節(jié)點里面都包含大廠面經(jīng)、學(xué)習(xí)筆記、源碼講義、實戰(zhàn)項目、講解視頻
如果你覺得這些內(nèi)容對你有幫助,可以添加下面V無償領(lǐng)取?。▊渥ndroid)
最后
總而言之,成功是留給準(zhǔn)備好的人的。無論是參加什么面試,都要做好充足的準(zhǔn)備,注意好面試的禮儀和穿著,向面試官表現(xiàn)出自己的熱忱與真誠就好。即使最后沒有過關(guān),也要做好經(jīng)驗的總結(jié),為下一次面試做好充足準(zhǔn)備。
這里我為大家準(zhǔn)備了一些我在面試后整理的面試專題資料,除了面試題,還總結(jié)出了互聯(lián)網(wǎng)公司Android程序員面試涉及到的絕大部分面試題及答案,并整理做成了文檔,以及系統(tǒng)的進階學(xué)習(xí)視頻資料,免費分享給大家,希望能幫助到你面試前的復(fù)習(xí),且找到一個好的工作,也節(jié)省大家在網(wǎng)上搜索資料的時間來學(xué)習(xí)。
畢竟不管遇到什么樣的面試官,去面試首先最主要的就是自己的實力,只要實力夠硬,技術(shù)夠強,就不怕面試拿不到offer!
想要面試順通嘛,趕緊領(lǐng)取下面的面試資料為之后的面試做足準(zhǔn)備叭!這里提前祝各位面試成功!
資料領(lǐng)取方式:??Android架構(gòu)設(shè)計
為什么某些人會一直比你優(yōu)秀,是因為他本身就很優(yōu)秀還一直在持續(xù)努力變得更優(yōu)秀,而你是不是還在滿足于現(xiàn)狀內(nèi)心在竊喜!希望讀到這的您能點個小贊和關(guān)注下我,以后還會更新技術(shù)干貨,謝謝您的支持!文章來源:http://www.zghlxwxcb.cn/news/detail-848884.html
先最主要的就是自己的實力,只要實力夠硬,技術(shù)夠強,就不怕面試拿不到offer!
想要面試順通嘛,趕緊領(lǐng)取下面的面試資料為之后的面試做足準(zhǔn)備叭!這里提前祝各位面試成功!
資料領(lǐng)取方式:??Android架構(gòu)設(shè)計
[外鏈圖片轉(zhuǎn)存中…(img-sNRE6syB-1711171591646)]
[外鏈圖片轉(zhuǎn)存中…(img-eXje5M5q-1711171591646)]
為什么某些人會一直比你優(yōu)秀,是因為他本身就很優(yōu)秀還一直在持續(xù)努力變得更優(yōu)秀,而你是不是還在滿足于現(xiàn)狀內(nèi)心在竊喜!希望讀到這的您能點個小贊和關(guān)注下我,以后還會更新技術(shù)干貨,謝謝您的支持!
文章來源地址http://www.zghlxwxcb.cn/news/detail-848884.html
到了這里,關(guān)于Android獲取本機各種類型文件列表(音樂、視頻,作為字節(jié)跳動面試官的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!