ManagedQuery在Android中已被弃用,推荐使用ContentResolver来代替,以下是使用ContentResolver进行查询的示例:
ContentResolver contentResolver = getContentResolver();
Uri uri = Uri.parse("content://com.example.provider/book");
String[] projection = {"_id", "name", "author"};
Cursor cursor = contentResolver.query(uri, projection, null, null, null);
if (cursor != null) {
while (cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndex("_id"));
String name = cursor.getString(cursor.getColumnIndex("name"));
String author = cursor.getString(cursor.getColumnIndex("author"));
// 处理查询结果
}
}
if (cursor != null) {
cursor.close();
}
请注意,这只是一个基本示例,具体的查询条件和操作根据实际需求进行调整。