How insert the contact info on the existing contact in Android 1.6? -


I have the contact's name, phone number and e-mail information. I just insert additional email and phone for existing contact Want to My questions are

  1. How can I get a contact or already exist or not?
  2. How to insert values ​​in additional or secondary address options?

Thanks in advance.

There are new conticts APIs in the official document.

First, look at the raw contact ID along with your criteria, such as name:

  last string name = "reader"; // Find the contact strings of "Reader" = String.format ("% s =? And% s = '% s'", data .digre, data .mmttee, phone.contENT_ITEM_TYPE); String [] project = new string [] {Data.RAW_CONTACT_ID}; Cursor c = getContentResolver () Query (Data.CONTENT_URI, project, selection, new string [] {name}, null); Long raw resource id = -1; If (c.moveToFirst ()) {rawContactId = c.getLong (c.getColumnIndex (Data.RAW_CONTACT_ID)); } C. Close ();  

Second, use rawContactId to add an entry in Contacts:

  ContentValues ​​value = new content value (); Values.put (Data.RAW_CONTACT_ID, rawContactId); Values.put (Data.MIMETYPE, phone.contENT_ITEM_TYPE); Values.put (phone number, "1-800-GOOG-411"); Values.put (phone .type, phone.TYPE_CUSTOM); Values.put (Phone.LABEL, "Free Directory Support"); Uri DataURI = Received Resolver (). Insert (data. CONTENT_URI, value);  

Do not forget the PS permissions:

  & lt; Usage-permission Android: name = "android.permission.READ_CONTACTS" & gt; & Lt; / Usage-permission & gt; & Lt; Usage-permission Android: name = "android.permission.WRITE_CONTACTS" & gt; & Lt; / Usage-permission & gt;  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -