android SQLite (Cursor SQLiteDatabase SQLiteOpenHelper ContentValues ContentProvider) 总结

一直在零零碎碎的用着SQLite,包括什么Cursor SQLiteDatabase SQLiteOpenHelper ContentValues ContentProvider等等
但是每次回头使用总是觉得有点乱,今天总结一下,献给和我一样的小菜鸟。

先来一个引子:

在android DDMS里面data\data\com.android.providers.media的数据库external-cef1c12.db里面存放了两个table,

其中Media放的是真正地图片,Thumbnails放的是图片的缩略图,缩略图是android系统自动生成的

下面两段代码时读取缩略图和图片

/**
* 读取缩略图
*/
private ArrayList<PhotoItem> getPhotosInfo()
{
ArrayList
<PhotoItem> photolist = new ArrayList<PhotoItem>();
Cursor cursor
= getContentResolver().query(
Thumbnails.EXTERNAL_CONTENT_URI,
null, null, null, null);
//Thumbnails.EXTERNAL_CONTENT_URI存放的是缩略图的url
if (cursor.moveToFirst())
{
do
{
PhotoItem pi
= new PhotoItem();
pi.ImageID
= cursor.getInt(cursor
.getColumnIndex(Thumbnails.IMAGE_ID));
pi.photoPath
= cursor.getString(cursor
.getColumnIndex(Thumbnails.DATA));
photolist.add(pi);
}
while (cursor.moveToNext());
}
cursor.close();
return photolist;
}
/**
	 * 读取缩略图
	 */
	private ArrayList<PhotoItem> getPhotosInfo()
	{
		ArrayList<PhotoItem> photolist = new ArrayList<PhotoItem>();
		Cursor cursor = getContentResolver().query(
				Thumbnails.EXTERNAL_CONTENT_URI, null, null, null, null);
		//Thumbnails.EXTERNAL_CONTENT_URI存放的是缩略图的url
		if (cursor.moveToFirst())
		{
			do
			{
				PhotoItem pi = new PhotoItem();
				pi.ImageID = cursor.getInt(cursor
						.getColumnIndex(Thumbnails.IMAGE_ID));
				pi.photoPath = cursor.getString(cursor
						.getColumnIndex(Thumbnails.DATA));
				photolist.add(pi);
			}
			while (cursor.moveToNext());
		}
		cursor.close();
		return photolist;
	}

未完,待续

posted on 2011-04-20 17:19  可乐boyupeng  阅读(638)  评论(0编辑  收藏  举报