├── README.md ├── phone ├── FileManager.java ├── FileUtils.java ├── PinyinUtils.java ├── bean │ ├── AppInfo.java │ ├── FileBean.java │ ├── FileItem.java │ ├── ImgFolderBean.java │ ├── Music.java │ └── Video.java └── libs │ └── pinyin4j-2.5.0.jar └── utils ├── OpenFileUtil.java ├── ShareSDKUtils.java └── TimeUtils.java /README.md: -------------------------------------------------------------------------------- 1 | ### 介绍 2 | 3 | 本仓库为博客提供源码的仓库 4 | 5 | ### 涉及的博客文章 6 | 7 | [TimeUtils,有关时间处理的工具类](http://www.jianshu.com/p/213f04ceb388) 8 | 9 | [Android获取本机各种类型文件列表(音乐、视频、图片、文档等)](http://www.jianshu.com/p/190ec8ff3e6c) 10 | 11 | [ShareSDKUtils,封装的分享工具类,使用默认的GUI或者自定义分享某个平台](http://www.jianshu.com/p/d7c86033a3b1) 12 | 13 | [Android中如何使用代码打开各种类型的文件](http://www.jianshu.com/p/1414101858c1) 14 | 15 | [PinyinUtils,拼音工具类](http://www.jianshu.com/p/6e3eed117342) 16 | 17 | ### CSDN和简书地址 18 | 19 | [我的CSDN地址](http://blog.csdn.net/chay_chan?viewmode=contents) 20 | 21 | [我的简书地址](http://www.jianshu.com/u/275ef936c427) 22 | 23 | ### 支持和鼓励 24 | 25 | 如果觉得对你有帮助的话,可以关注和支持下我的博客,相互学习和进步,若有什么疑问或者意见,可以在我的博客中评论,我将会为你解答。 -------------------------------------------------------------------------------- /phone/FileManager.java: -------------------------------------------------------------------------------- 1 | package com.chaychan.blogfileresource.phone; 2 | 3 | import android.content.ContentResolver; 4 | import android.content.Context; 5 | import android.content.pm.ApplicationInfo; 6 | import android.content.pm.PackageInfo; 7 | import android.content.pm.PackageManager; 8 | import android.database.Cursor; 9 | import android.graphics.Bitmap; 10 | import android.graphics.BitmapFactory; 11 | import android.graphics.drawable.Drawable; 12 | import android.provider.MediaStore; 13 | 14 | import com.chaychan.blogfileresource.phone.bean.AppInfo; 15 | import com.chaychan.blogfileresource.phone.bean.FileBean; 16 | import com.chaychan.blogfileresource.phone.bean.ImgFolderBean; 17 | import com.chaychan.blogfileresource.phone.bean.Music; 18 | import com.chaychan.blogfileresource.phone.bean.Video; 19 | 20 | import java.io.File; 21 | import java.io.FilenameFilter; 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | /** 26 | * @创建人 chaychan 27 | * @创建时间 2016/7/23 14:34 28 | * @描述 文件管理者, 可以获取本机的各种文件 29 | */ 30 | public class FileManager { 31 | 32 | private static FileManager mInstance; 33 | private static Context mContext; 34 | private static ContentResolver mContentResolver; 35 | private static Object mLock = new Object(); 36 | 37 | public static FileManager getInstance(Context context){ 38 | if (mInstance == null){ 39 | synchronized (mLock){ 40 | if (mInstance == null){ 41 | mInstance = new FileManager(); 42 | mContext = context; 43 | mContentResolver = context.getContentResolver(); 44 | } 45 | } 46 | } 47 | return mInstance; 48 | } 49 | 50 | /** 51 | * 获取本机音乐列表 52 | * @return 53 | */ 54 | public List getMusics() { 55 | ArrayList musics = new ArrayList<>(); 56 | Cursor c = null; 57 | try { 58 | c = mContentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, 59 | MediaStore.Audio.Media.DEFAULT_SORT_ORDER); 60 | 61 | while (c.moveToNext()) { 62 | String path = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));// 路径 63 | 64 | if (!new File(path).exists()) { 65 | continue; 66 | } 67 | 68 | String name = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME)); // 歌曲名 69 | String album = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM)); // 专辑 70 | String artist = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST)); // 作者 71 | long size = c.getLong(c.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE));// 大小 72 | int duration = c.getInt(c.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION));// 时长 73 | int time = c.getInt(c.getColumnIndexOrThrow(MediaStore.Audio.Media._ID));// 歌曲的id 74 | // int albumId = c.getInt(c.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID)); 75 | 76 | Music music = new Music(name, path, album, artist, size, duration); 77 | musics.add(music); 78 | } 79 | 80 | } catch (Exception e) { 81 | e.printStackTrace(); 82 | } finally { 83 | if (c != null) { 84 | c.close(); 85 | } 86 | } 87 | return musics; 88 | } 89 | 90 | /** 91 | * 获取本机视频列表 92 | * @return 93 | */ 94 | public List