views:

694

answers:

2

Hi,

I have added one contact to android by following code.

 ContentValues values = new ContentValues();
 Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values);
 long rawContactId = ContentUris.parseId(rawContactUri);

 values.clear();
 values.put(Data.RAW_CONTACT_ID, rawContactId);
 values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
 values.put(StructuredName.DISPLAY_NAME, "Mike Sullivan");
 getContentResolver().insert(Data.CONTENT_URI, values);

It shows up on emulator 2.1, but when i am going to delete it manually by "delete contact" option, its not deleteing from emulator.

If I edit some thing on it then only it deletes.

How can i directly delete it from menu ?

Thanks in advance...

A: 

Could you please use the below code to add the contact. This will not affect your emulator to delete contact from menu without editing the same.

import android.provider.Contacts.People; 

public void addvaluestocontent()
{
    ContentValues values = new ContentValues();

    values.put(People.NAME, "Abraham Lincoln");
    values.put(People._ID, "1");
    values.put(People.NUMBER, "23333");

    Uri uri = getContentResolver().insert(People.CONTENT_URI, values);
}
Maneesh
yes, I have tried by this on emulator 1.6 it was working but People.CONTENT_URI is depricated in android 2.1 thats why i used that code. I was also getting exception while updating contact in android 2.1 with People.CONTENT_URI.People.CONTENT_URI.
Rishabh
A: 

You have to save one more field, either "Given Name" or "Family Name". You can test it manually by saving contacts. First try to save manaully only number and then with saving contacts with both name and number.

Maneesh