Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ArrayList<ContentProviderOperation> ops =
- new ArrayList<>();
- int rawContactInsertIndex = ops.size();
- ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
- .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, accountType)
- .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, ACCOUNT_NAME)
- .withValue(ContactsContract.RawContacts.SYNC1, "myInternalId")
- .build());
- ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
- .withValueBackReference(ContactsContract.RawContacts.Data.RAW_CONTACT_ID, rawContactInsertIndex)
- .withValue(ContactsContract.RawContacts.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
- .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, "Test User")
- .build());
- getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
- ContentResolver cr = this.getContentResolver();
- Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
- if (cur.getCount() > 0) {
- while (cur.moveToNext()) {
- String id = cur.getString(cur.getColumnIndex(
- ContactsContract.Contacts._ID));
- String name = cur.getString(cur.getColumnIndex(
- ContactsContract.Contacts.DISPLAY_NAME));
- String sync1 = null;
- int sync1Index = cur.getColumnIndex(ContactsContract.RawContacts.SYNC1);
- if (sync1Index >= 0) {
- sync1 = cur.getString(sync1Index);
- }
- System.out.println("Contact id=" + id + " name=" + name + " sync1=" + sync1);
- }
- }
- cur.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement