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();
}
請注意,這只是一個基本示例,具體的查詢條件和操作根據實際需求進行調整。