Cannot bind argument at index 2 because the index is out of range. The state
碰到这种问题,说明selection参数里面有两个?占位符,selectionArgs数组参数里面没有两个条件参数,导致索引越界
or 跟java中 || 同理,表示查询的mine_type可以是image/jpeg也可以是image/png类型
Cursor cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, "mime_type=? or mime_type=?", new String[]{"image/jpeg", "image/png"},
null);
还有一个and 跟java中 && 同理,表示查询的mine_type可以是image/jpeg也可以是image/png类型并且时间戳要大于timestamp,因为timestamp是long类型所以不能用占位符?,放到后面的selectionArgs String数组参数中会报错,可以直接拼接在参数selection后面
Cursor cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
null,
"(mime_type=? or mime_type=?) and date_added>"+timestamp,
new String[]{"image/jpeg", "image/png"},
null);