hi all,
 i am beginner in android development.i am trying to add, delete and
update contact information using my own application. when i try to add
a contact, it is not getting added. please help me.

My code is:

ArrayList<ContentProviderOperation> ops = new
ArrayList<ContentProviderOperation>();
                                 int rawContactInsertIndex =
ops.size();
 
ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
                                  
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE,"Google")
                                  
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME,"[email protected]") 
.build());

 
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                                 
.withValueBackReference(Data.RAW_CONTACT_ID,rawContactInsertIndex)
                                 
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
                                 
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
name)
                                 .build());


 
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                                  
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,
rawContactInsertIndex)
                                  
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
                                  
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER,
phone)
                                  
.withValue(ContactsContract.CommonDataKinds.Phone.TYPE,
phoneType)
                                  .build());
 
ops.add(ContentProviderOperation.newInsert(ContactsContract
                                  .Data.CONTENT_URI)
                                  
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,rawContactInsertIndex)
                                  
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
                                  
.withValue(ContactsContract.CommonDataKinds.Email.DATA,
email)
                                  
.withValue(ContactsContract.CommonDataKinds.Email.TYPE,
emailType)
                                  .build());

                                  try {
 
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
                                    Context ctx =
getApplicationContext();
                                    CharSequence txt = "Contact " +
name +" added successfully";
                                                 int duration =
Toast.LENGTH_LONG;
                                                 Toast toast =
Toast.makeText(ctx, txt, duration);
                                                 toast.show();
                                } catch (Exception e) {
 
Toast.makeText(getApplicationContext(),"error",Toast.LENGTH_LONG).show();


                                }


Note: I don't have any in-built account name google.is it mandatory to
specific the ACCOUNT NAME and ACCOUNT TYPE?

i am also having problem in deleting and updating the contact. please
help me in this issue

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