Android如何通过content provider构建媒体文件数据库
2010-09-27 01:52:00 来源:WEB开发网Android为 Camera,Audio,Video等媒体文件提供MediaProvider用于数据的保存,删除,检索等。MediaProvider实现了 ContentProvider类的几个操作SQL的重要方法如insert ,delete, updata, query。MediaProvider中DatabaseHelper类用于获取与创建Database。
private static final class DatabaseHelper extends SQLiteOpenHelper {
final Context mContext;
final boolean mInternal; // True if this is the internal database
// In memory caches of artist and album data.
HashMap< String, Long> mArtistCache = new HashMap< String, Long>();
HashMap< String, Long> mAlbumCache = new HashMap< String, Long>();
public DatabaseHelper(Context context, String name, boolean internal) {
super(context, name, null, DATABASE_VERSION);
mContext = context;
mInternal = internal;
}
/**
* Creates database the first time we try to open it.
*/
@Override //第一次打开数据库时创建Table
public void onCreate(final SQLiteDatabase db) {
updateDatabase(db, mInternal, 0, DATABASE_VERSION);
}
以Camera的image文件文件为例,数据库在第一次使用的时候被创建,对于image文件,SQL在updateDatabase为其创建一个table:
db.execSQL("CREATE TABLE IF NOT EXISTS images (" +
"_id INTEGER PRIMARY KEY," + //文件保存的序号
"_data TEXT," + //记录image 文件保存路径
"_size INTEGER," + //文件大小
"_display_name TEXT," + //图片名称
"mime_type TEXT," + //文件类型
"title TEXT," +
"date_added INTEGER," +
"date_modified INTEGER," +
"description TEXT," +
"picasa_id TEXT," +
"isprivate INTEGER," +
"latitude DOUBLE," +
"longitude DOUBLE," +
"datetaken INTEGER," +
"orientation INTEGER," +
"mini_thumb_magic INTEGER," +
- ››Android 当修改一些代码时,使用什么编译命令可以最...
- ››Android 如何添加一个apk使模拟器和真机都编译进去...
- ››Android 修改Camera拍照的默认保存路径
- ››Android 如何修改默认输入法
- ››如何检查oracle的归档空间是否满了
- ››如何在浏览器中打开PDF文件并实现预览的思路与代码...
- ››如何改Win7系统我的文档保存位置
- ››android开发中finish()和System.exit(0)的区别
- ››Android手势识别简单封装类
- ››android中查看项目数字证书的两种方法
- ››Android中获取IMEI码的办法
- ››android 相机报错 setParameters failed
更多精彩
赞助商链接