Android ContentResolver ??????????????????????????????,??????????? ContentResolver:
-
?? Content Resolver ????:
- ??
query()
??????????? URI?????(???????)???????(??????)??????????? - ??:??????????????
Uri contactsUri = ContactsContract.Contacts.CONTENT_URI; String[] projection = {ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.Phone_NUMBERS}; String selection = "((" + ContactsContract.Contacts.DISPLAY_NAME + " LIKE ?) AND (" + ContactsContract.Contacts.Phone_NUMBERS + " LIKE ?))"; String[] selectionArgs = {"%John%", "3%"}; Cursor cursor = getContentResolver().query(contactsUri, projection, selection, selectionArgs, null);
- ??
-
????:
- ??
insert()
??????????? URI ???????(? ContentValues ?????)? - ??:????????????
Uri contactsUri = ContactsContract.Contacts.CONTENT_URI; ContentValues contentValues = new ContentValues(); contentValues.put(ContactsContract.Contacts.DISPLAY_NAME, "John Doe"); contentValues.put(ContactsContract.Contacts.Phone_NUMBERS, "123-456-7890"); Uri newContactUri = getContentResolver().insert(contactsUri, contentValues);
- ??
-
????:
- ??
update()
??????????? URI???????(? ContentValues ?????)???????? - ??:???????????
Uri contactsUri = ContactsContract.Contacts.CONTENT_URI; String selection = ContactsContract.Contacts._ID + "=?"; String[] selectionArgs = {"1"}; ContentValues contentValues = new ContentValues(); contentValues.put(ContactsContract.Contacts.Phone_NUMBERS, "098-765-4321"); getContentResolver().update(contactsUri, contentValues, selection, selectionArgs);
- ??
-
????:
- ??
delete()
??????????? URI ???????? - ??:???? "John Doe" ?????
Uri contactsUri = ContactsContract.Contacts.CONTENT_URI; String selection = ContactsContract.Contacts.DISPLAY_NAME + "=?"; String[] selectionArgs = {"John Doe"}; getContentResolver().delete(contactsUri, selection, selectionArgs);
- ??
-
?? Content Resolver ??????:
- ???????,?????
ContentObserver
?????onChange()
?????,??getContentResolver().registerContentObserver()
???? ContentObserver? - ??:??????????????
Uri contactsUri = ContactsContract.Contacts.CONTENT_URI; getContentResolver().registerContentObserver(contactsUri, true, new ContentObserver(new Handler()) { @Override public void onChange(boolean selfChange) { super.onChange(selfChange); // ???????????? } });
- ???????,?????
-
?? Content Resolver ???????????:
- ????????????,???????? Content URI???,?? URI ???????????????????
- ??:???????????????
Uri imagesUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; String[] projection = {MediaStore.Images.Media._ID, MediaStore.Images.Media.DISPLAY_NAME}; Cursor cursor = getContentResolver().query(imagesUri, projection, null, null, null);
??????????,????????? Android ContentResolver ???????????????????