WEB开发网
开发学院手机开发Android 开发 Android如何通过content provider构建媒体文件数据... 阅读

Android如何通过content provider构建媒体文件数据库

 2010-09-27 01:52:00 来源:WEB开发网   
核心提示:Android为 Camera,Audio,Android如何通过content provider构建媒体文件数据库,Video等媒体文件提供MediaProvider用于数据的保存,删除,private static final class DatabaseHelper extends SQLiteOpenHelpe

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," +

1 2 3 4 5  下一页

Tags:Android 如何 通过

编辑录入:coldstar [复制链接] [打 印]
赞助商链接