max
max

Reputation: 31

New programmatically added contact not visible in Contacts application

I'm developping an application in Android 1.6 (and can't use 2.0 or older).

I add a new contact on my phone as following :

ContentValues contentValues = new ContentValues();
contentValues.put(Contacts.People.NAME, name);

Uri contactUri = this.getContentResolver().insert(Contacts.People.CONTENT_URI, contentValues);

After that, I add phone numbers in the same way. It works as I am able to view the new added contact with following code :

Intent intent = new Intent(Intent.ACTION_VIEW, contactUri);
this.startActivity(intent);

My problem is that, after adding and viewing the new contact, I can't see it in Contacts application unless I synchronized all my contacts (I also did a search with the contact's name, found it, nevertheless it wasn't added in contacts list).

How can I programmatically update the contacts in order to immediately have my new contact added in Contacts application ?

Thank you !

Upvotes: 0

Views: 2557

Answers (1)

max
max

Reputation: 31

I found the answer : after adding new contact (insert), add it to myContactsGroup with Contacts.People.addToMyContactsGroup() method :

// get new contact id :

int contactId = Integer.valueOf(contactUri.toString().substring(contactUri.toString().lastIndexOf("/")+1));

// add the new contact to myContactsGroup to have it in Contacts Application :

Contacts.People.addToMyContactsGroup(this.getContentResolver(), contactId);

Upvotes: 3

Related Questions