使用可能なすべてのフィールドにデータを含む連絡先を保存しようとしています。しかし、何らかの理由ですべてのデータが保存されるわけではありません。機能していると思われるフィールドのみは次のとおりです。
- 構造化された名前
- 電話
- 私は
- 組織
誰かが私の間違いがどこにあるかを教えてもらえますか?
public void saveContact(Context context)
{
ArrayList<ContentProviderOperation> op_list = new ArrayList<ContentProviderOperation>();
op_list.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
.withValue(RawContacts.ACCOUNT_TYPE, null)
.withValue(RawContacts.ACCOUNT_NAME, null)
.build());
op_list.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, 0)
.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredName.DISPLAY_NAME, "Dislayname")
.withValue(StructuredName.PREFIX, "Prefix")
.withValue(StructuredName.GIVEN_NAME, "First")
.withValue(StructuredName.FAMILY_NAME, "Last")
.withValue(StructuredName.MIDDLE_NAME, "Middle")
.withValue(StructuredName.SUFFIX, "Suffix")
.build());
op_list.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValue(Data.RAW_CONTACT_ID, 0)
.withValue(Data.MIMETYPE, Nickname.CONTENT_ITEM_TYPE)
.withValue(Nickname.NAME, "Nickname")
.withValue(Nickname.TYPE, Nickname.TYPE_SHORT_NAME)
.build());
op_list.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, 0)
.withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
.withValue(Phone.TYPE, Phone.TYPE_WORK)
.withValue(Phone.NUMBER, "66666666")
.withValue(Phone.LABEL, "")
.build());
op_list.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValue(Data.RAW_CONTACT_ID, 0)
.withValue(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE)
.withValue(Email.TYPE, Email.TYPE_WORK)
.withValue(Email.DATA, "test@test.com")
.build());
op_list.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValue(Data.RAW_CONTACT_ID, 0)
.withValue(Data.MIMETYPE, Website.CONTENT_ITEM_TYPE)
.withValue(Website.TYPE, Website.TYPE_WORK)
.withValue(Website.URL, "www.site.com")
.build());
op_list.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValue(Data.RAW_CONTACT_ID, 0)
.withValue(Data.MIMETYPE, StructuredPostal.CONTENT_ITEM_TYPE)
.withValue(StructuredPostal.TYPE, StructuredPostal.TYPE_HOME)
.withValue(StructuredPostal.STREET, "TEST STREET")
.withValue(StructuredPostal.CITY, "TEST CITY")
.withValue(StructuredPostal.REGION, "TEST REGION")
.withValue(StructuredPostal.POSTCODE, "00000")
.withValue(StructuredPostal.COUNTRY, "TEST COUNTRY")
.withValue(StructuredPostal.NEIGHBORHOOD, "TEST NEIGHBORHOOD")
.withValue(StructuredPostal.POBOX, "TEST POBOX")
.build());
op_list.add(ContentProviderOperation
.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, 0)
.withValue(Data.MIMETYPE, ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE )
.withValue(ContactsContract.CommonDataKinds.Organization.COMPANY, "Company")
.withValue(ContactsContract.CommonDataKinds.Organization.TITLE, "Job Title")
.withValue(ContactsContract.CommonDataKinds.Organization.JOB_DESCRIPTION, "Job description/position")
.withValue(ContactsContract.CommonDataKinds.Organization.DEPARTMENT, "Department")
.withValue(ContactsContract.CommonDataKinds.Organization.OFFICE_LOCATION, "Office location")
.withValue(ContactsContract.CommonDataKinds.Organization.SYMBOL, "Symbol")
.withValue(ContactsContract.CommonDataKinds.Organization.PHONETIC_NAME, "Phonetic name")
.withValue(ContactsContract.CommonDataKinds.Organization.TYPE, ContactsContract.CommonDataKinds.Organization.TYPE_WORK)
.build());
op_list.add(ContentProviderOperation
.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, 0)
.withValue(Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Im.DATA, "skype@a.com")
.withValue(ContactsContract.CommonDataKinds.Im.TYPE, Im.TYPE_WORK)
.withValue(ContactsContract.CommonDataKinds.Im.PROTOCOL, Im.PROTOCOL_SKYPE)
.build());
op_list.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValue(Data.RAW_CONTACT_ID, 0)
.withValue(Data.MIMETYPE, Nickname.CONTENT_ITEM_TYPE)
.withValue(Note.NOTE, "Note")
.build());
op_list.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValue(Data.RAW_CONTACT_ID, 0)
.withValue(Data.MIMETYPE, android.provider.ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE)
.withValue(android.provider.ContactsContract.CommonDataKinds.Event.START_DATE, "2013-06-06")
.withValue(android.provider.ContactsContract.CommonDataKinds.Event.TYPE, android.provider.ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY)
.withValue(android.provider.ContactsContract.CommonDataKinds.Event.LABEL, "Birthday")
.build());
op_list.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValue(Data.RAW_CONTACT_ID, 0)
.withValue(Data.MIMETYPE, Relation.CONTENT_ITEM_TYPE)
.withValue(Relation.NAME, "Relation name")
.withValue(Relation.TYPE, Relation.TYPE_BROTHER)
.build());
try {
context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, op_list);
} catch(Exception e) {
Log.d("contacts", "saveContact", e);
}
}