概要:
由于手机自带的文件管功能太弱,而第三方的文件管理软件又非常的混乱,朋友们是否为此而头疼呢?
需求:
开发文件管理器,它不仅在数据统计和文件管理方面都表现的非常方便,还拥有独特的无线管理和网盘模式。
设计:
分类索引、目录索引、无线管理、电脑互传、网盘管理
开发:
工具类的设计:Image、Audio、Viedo 提供外部接口方法 getList();
直接上代码:大家可以在此基础上写成工具包(模块式开发)
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
public class Image { private int id; private String title; private String displayName; private String mimeType; private String path; private long size; public Image() { super(); } /** * @param id * @param title * @param displayName * @param mimeType * @param path * @param size */ public Image(int id, String title, String displayName, String mimeType, String path, long size) { super(); this.id = id; this.title = title; this.displayName = displayName; this.mimeType = mimeType; this.path = path; this.size = size; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDisplayName() { return displayName; } public void setDisplayName(String displayName) { this.displayName = displayName; } public String getMimeType() { return mimeType; } public void setMimeType(String mimeType) { this.mimeType = mimeType; } public String getPath() { return path; } public void setPath(String path) { this.path = path; } public long getSize() { return size; } public void setSize(long size) { this.size = size; }
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
package single.find; import java.util.ArrayList; import java.util.List; import android.content.Context; import android.database.Cursor; import android.provider.MediaStore; public class ImageProvider{ private Context context; public ImageProvider(Context context) { this.context = context; } public List<Image> getList() { List<Image> list = null; if (context != null) { Cursor cursor = context.getContentResolver().query( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null, null); if (cursor != null) { list = new ArrayList<Image>(); while (cursor.moveToNext()) { int id = cursor .getInt(cursor .getColumnIndexOrThrow(MediaStore.Images.Media._ID)); String title = cursor .getString(cursor .getColumnIndexOrThrow(MediaStore.Images.Media.TITLE)); String path = cursor .getString(cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA)); String displayName = cursor .getString(cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME)); String mimeType = cursor .getString(cursor .getColumnIndexOrThrow(MediaStore.Images.Media.MIME_TYPE)); long size = cursor .getLong(cursor .getColumnIndexOrThrow(MediaStore.Images.Media.SIZE)); Image audio = new Image(id, title, displayName, mimeType, path, size); list.add(audio); } cursor.close(); } } return list; } }
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
package single.find; public class Audio { private int id; private String title; private String album; private String artist; private String path; private String displayName; private String mimeType; private long duration; private long size; /** * */ public Audio() { super(); } /** * @param id * @param title * @param album * @param artist * @param path * @param displayName * @param mimeType * @param duration * @param size */ public Audio(int id, String title, String album, String artist, String path, String displayName, String mimeType, long duration, long size) { super(); this.id = id; this.title = title; this.album = album; this.artist = artist; this.path = path; this.displayName = displayName; this.mimeType = mimeType; this.duration = duration; this.size = size; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getAlbum() { return album; } public void setAlbum(String album) { this.album = album; } public String getArtist() { return artist; } public void setArtist(String artist) { this.artist = artist; } public String getPath() { return path; } public void setPath(String path) { this.path = path; } public String getDisplayName() { return displayName; } public void setDisplayName(String displayName) { this.displayName = displayName; } public String getMimeType() { return mimeType; } public void setMimeType(String mimeType) { this.mimeType = mimeType; } public long getDuration() { return duration; } public void setDuration(long duration) { this.duration = duration; } public long getSize() { return size; } public void setSize(long size) { this.size = size; } }
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
package single.find; import java.util.ArrayList; import java.util.List; import android.content.Context; import android.database.Cursor; import android.provider.MediaStore; public class AudioProvider{ private Context context; public AudioProvider(Context context) { this.context = context; } public List<Audio> getList() { List<Audio> list = null; if (context != null) { Cursor cursor = context.getContentResolver().query( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null); if (cursor != null) { list = new ArrayList<Audio>(); while (cursor.moveToNext()) { int id = cursor.getInt(cursor .getColumnIndexOrThrow(MediaStore.Audio.Media._ID)); String title = cursor .getString(cursor .getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE)); String album = cursor .getString(cursor .getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM)); String artist = cursor .getString(cursor .getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST)); String path = cursor .getString(cursor .getColumnIndexOrThrow(MediaStore.Audio.Media.DATA)); String displayName = cursor .getString(cursor .getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME)); String mimeType = cursor .getString(cursor .getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE)); long duration = cursor .getInt(cursor .getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION)); long size = cursor .getLong(cursor .getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE)); Audio audio = new Audio(id, title, album, artist, path, displayName, mimeType, duration, size); list.add(audio); } cursor.close(); } } return list; } }
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
package single.find; public class Video { private int id; private String title; private String album; private String artist; private String displayName; private String mimeType; private String path; private long size; private long duration; /** * */ public Video() { super(); } /** * @param id * @param title * @param album * @param artist * @param displayName * @param mimeType * @param data * @param size * @param duration */ public Video(int id, String title, String album, String artist, String displayName, String mimeType, String path, long size, long duration) { super(); this.id = id; this.title = title; this.album = album; this.artist = artist; this.displayName = displayName; this.mimeType = mimeType; this.path = path; this.size = size; this.duration = duration; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getAlbum() { return album; } public void setAlbum(String album) { this.album = album; } public String getArtist() { return artist; } public void setArtist(String artist) { this.artist = artist; } public String getDisplayName() { return displayName; } public void setDisplayName(String displayName) { this.displayName = displayName; } public String getMimeType() { return mimeType; } public void setMimeType(String mimeType) { this.mimeType = mimeType; } public String getPath() { return path; } public void setPath(String path) { this.path = path; } public long getSize() { return size; } public void setSize(long size) { this.size = size; } public long getDuration() { return duration; } public void setDuration(long duration) { this.duration = duration; } }
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
package single.find; import java.util.ArrayList; import java.util.List; import android.content.Context; import android.database.Cursor; import android.provider.MediaStore; public class VideoProvider{ private Context context; public VideoProvider(Context context) { this.context = context; } public List<Video> getList() { List<Video> list = null; if (context != null) { Cursor cursor = context.getContentResolver().query( MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null, null, null); if (cursor != null) { list = new ArrayList<Video>(); while (cursor.moveToNext()) { int id = cursor.getInt(cursor .getColumnIndexOrThrow(MediaStore.Video.Media._ID)); String title = cursor .getString(cursor .getColumnIndexOrThrow(MediaStore.Video.Media.TITLE)); String album = cursor .getString(cursor .getColumnIndexOrThrow(MediaStore.Video.Media.ALBUM)); String artist = cursor .getString(cursor .getColumnIndexOrThrow(MediaStore.Video.Media.ARTIST)); String displayName = cursor .getString(cursor .getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME)); String mimeType = cursor .getString(cursor .getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE)); String path = cursor .getString(cursor .getColumnIndexOrThrow(MediaStore.Video.Media.DATA)); long duration = cursor .getInt(cursor .getColumnIndexOrThrow(MediaStore.Video.Media.DURATION)); long size = cursor .getLong(cursor .getColumnIndexOrThrow(MediaStore.Video.Media.SIZE)); Video video = new Video(id, title, album, artist, displayName, mimeType, path, size, duration); list.add(video); } cursor.close(); } } return list; } }
继续关注: android文件管理器的开发(二)