获取手机的本地图片就是使用ContentResolver类查询本地的数据库,只不过需要使用该类进行查询,并且该类中提供了增删改查的响应的方法。本篇博文并不对ContentResolver进行详细的介绍,相比大家在书上面已经了解到了ContentResolver的用法,所以本篇博文主要对ContentResolver获取本地图片“解惑“。
本人在学习ContentResolver的时候一直很困惑的是ContentResolver查询的时候字段是如何设置的?不明白为什么是这样的字段,代码如下:
String[] projection = {
MediaStore.Images.Media._ID
};
Uri ext_uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String where = MediaStore.Images. + ">=?";
Cursor c = MediaStore.Images.Media.query(
mContentResolver,
ext_uri,
projection,
where,
new String[]{1 * 100 * 1024 + ""},
MediaStore.Images.Media.DATE_ADDED+" desc");
int columnIndex = c.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
这部分代码查询的是图片的ID值。一直不明白Media._ID、Media.DATE_ADDED、Media.SIZE这些字段很困