使用MediaStore.Images和 Cursor查詢本地圖片和圖片縮圖
先看一個例項:
String[] projection = { MediaStore.Images.Thumbnails._ID,MediaStore.Images.Thumbnails.DATA};
Cursor cursor = mActivity.getContentResolver().query(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,//指定縮圖資料庫的Uri
projection,//指定所要查詢的欄位
MediaStore.Images.Thumbnails._ID+ " = ?",//查詢條件
newString[] {"123" }, //查詢條件中問號對應的值
null);
cursor.moveToFirst();
String id = cursor.getString(0);
String data = cursor.getString(1);
查詢圖片縮圖資料庫,獲取id等於123的縮圖資訊。
轉換成Sql語句即為 select MediaStore.Images.Thumbnails._ID,MediaStore.Images.Thumbnails.DATA fromMediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI whereMediaStore.Images.Thumbnails._ID = 123
如果要查詢圖片,Uri地址為:MediaStore.Images.Media.EXTERNAL_CONTENT_URI
當要獲取縮圖時:Bitmap bitmap =MediaStore.Images.Thumbnails.getThumbnail (mActivity.getContentResolver(), id,Thumbnails.MICRO_KIND, null)