I have a small application that tries to insert a contact in Android
2.0 and it needs to link with every account type that can sync. This
part of the code works fine but then the contact does not show up in
the contacts app. The in_visible_group is set to 0 in the database.
How do I set this variable to 1 so that my contact is visible in the
contacts app. The following is my code
ArrayList<ContentProviderOperation> op_list = new
ArrayList<ContentProviderOperation>();
int rawContactInsertOperationBackRefIndex = 0;
AccountManager am = AccountManager.get(context);
Account[] accounts = am.getAccounts();
if(accounts != null && accounts.length > 0) {
for(int i = 0; i < accounts.length; i++) {
if(!accounts[i].name.contains(":")) {
Log.i(TAG, "Adding contact of name =
"+accounts[i].name+";
type = "+accounts[i].type);
// insert null account information (Android
will find it)
op_list.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE,
accounts[i].type)
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME,
accounts[i].name)
.build());
// insert new contact display name
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID,
rawContactInsertOperationBackRefIndex)
.withValue(Data.MIMETYPE,
StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredPostal.TYPE,
StructuredPostal.TYPE_HOME)
.withValue(StructuredName.DISPLAY_NAME,
name)
.withValue(StructuredName.GIVEN_NAME,
name)
.build());
// insert formatted postal address
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID,
rawContactInsertOperationBackRefIndex)
.withValue(Data.MIMETYPE,
StructuredPostal.CONTENT_ITEM_TYPE)
.withValue(StructuredPostal.FORMATTED_ADDRESS,
postalAddress)
.build());
rawContactInsertOperationBackRefIndex =
rawContactInsertOperationBackRefIndex + 3;
}
}
}
ContentProviderResult[] results =
context.getContentResolver().applyBatch(ContactsContract.AUTHORITY,
op_list);
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en