The problem is that the contact itself does not have visibility. The
visibility is dependent on which group the contact is a member of. You
don't see the contact in your list because by default the contact
manager only wants to show the contacts in the "My Contacts" group. In
your example if you go to your contact manager and go to the display
options and choose "All other contacts" on your Google account you
will see the newly added contact. This option will display the
contacts in that account that do not have any group membership.

You need to query the Group ids via ContactsContract.Groups and insert
a group id when creating a contact via
ContactsContract.CommonDataKinds.GroupMembership.

On May 6, 2:37 pm, Surendra <[email protected]> wrote:
> 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 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
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

Reply via email to