this soru ve yanıtını gördüm, ancak telefon bilgilerinin eklenmesi (ve hatta e-posta) hala iletişim bilgilerinin düzgün bir şekilde toplanmasına neden olmaz (Kişiler uygulamasını kontrol ettiğimde, aynı ad altında birden çok giriş görüyorum).Program aracılığıyla eklerken, kişilerin düzgün bir şekilde nasıl toplanacağını nasıl edinirsiniz?
İşte test etmek için kullandığım kod. bunlar otomatik toplayarak değilseniz
//get the account
Account acct = null;
Account[] accounts = AccountManager.get(getContext()).getAccounts();
for (Account acc : accounts){
acct = acc;
}//assuming there's only one account in there (in my case I know there is)
//loop a few times, creating a new contact each time. In theory, if they have the same name they should aggregate
for(int i=0; i<3; i++){
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, acct.type)
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, acct.name)
.withValue(ContactsContract.RawContacts.AGGREGATION_MODE, ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT)
.build());
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, "ContactName")
.build());
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, "1234567890")
.withValue(ContactsContract.CommonDataKinds.Phone.TYPE, 1)
.build());
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Email.DATA, "[email protected]")
.withValue(ContactsContract.CommonDataKinds.Email.TYPE, 1)
.build());
try{
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
}
catch (Exception e) {
Log.e("Contacts", "Something went wrong during creation! " + e);
e.printStackTrace();
}
}
Oluşturulan kişileri adlarıyla farklı olsa bile nasıl bağlayacağınızı buldunuz mu? –
@androiddeveloper Üzgünüz, bu konuda çalışmayı bıraktım ve hiçbir zaman iyi bir cevap bulamadım – Matt
Tamam, sanırım ben senin örnek kullanarak çalışıyorum, bu yüzden bir cevap yazdım. Şey, benim bilmediğim daha fazla soru düşünmemi sağladı. –