<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4228853134948674154</id><updated>2024-09-28T18:36:23.451-07:00</updated><title type='text'>Email addresses in Android contacts</title><subtitle type='html'>Explains hot to insert an email address or update an already existing one, in an existing Android contact.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://email-addresses-in-android-contacts.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4228853134948674154/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://email-addresses-in-android-contacts.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ali Chousein</name><uri>http://www.blogger.com/profile/15925871269074773713</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZkW3e0y_5wV6XjWVRv1SFMaLy2adh8cu75E99Z3AY2M5Tjd9l4_lkSpSry7fV59BYbyetUqgsWBAz7PB_KaNa3AqKMUtd2okIoF8y0JgaMNK9cXyx_pcKoNnL2ZxX_A/s220/chousein.png'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4228853134948674154.post-4127844235182307807</id><published>2011-04-10T04:55:00.000-07:00</published><updated>2011-12-17T12:20:26.714-08:00</updated><title type='text'>How to insert and update email addresses in Android contacts</title><content type='html'>&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Verdana, sans-serif; margin-bottom: 0cm;&quot;&gt;Lately I&#39;ve been working to insert an email address or update an already existing one, in an existing Android contact. The examples I found from the Internet mainly focus on creating a contact entry from scratch and insering it into the list of contacts. I had to find the correct steps by trial and error and it took me some time before get it working. I decided to write a short blog about this experience, hoping that it might be useful for others and save time.&lt;/div&gt;&lt;div style=&quot;font-family: Verdana, sans-serif; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Verdana, sans-serif; margin-bottom: 0cm;&quot;&gt;Although there are alternative ways on how to insert and update an email address of an Android contact, I chose to work with &lt;a href=&quot;http://developer.android.com/reference/android/content/ContentProviderOperation.html&quot;&gt;ContentProviderOperation&lt;/a&gt;. This has the great advantage of applying many inserts and many updates in batch mode.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;font-family: Verdana, sans-serif; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Verdana, sans-serif; margin-bottom: 0cm;&quot;&gt;Below I provide a complete example which works out of the box for it&#39;s purpose. The same approach should work for other fields, like the postal address as well.&lt;/div&gt;&lt;div style=&quot;font-family: Verdana, sans-serif; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Verdana, sans-serif; margin-bottom: 0cm;&quot;&gt;Enjoy,&lt;/div&gt;&lt;div style=&quot;font-family: Verdana, sans-serif; margin-bottom: 0cm;&quot;&gt;-Ali&lt;/div&gt;&lt;div style=&quot;font-family: Verdana, sans-serif; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Verdana, sans-serif; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;/*&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;* Copyright (C) 2011 Ali Chousein&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;*&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;* Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;* you may not use this file except in compliance with the License.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;* You may obtain a copy of the License at&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;*&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;* &amp;nbsp; &amp;nbsp; &amp;nbsp;http://www.apache.org/licenses/LICENSE-2.0&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;*&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;* Unless required by applicable law or agreed to in writing, software&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;* distributed under the License is distributed on an &quot;AS IS&quot; BASIS,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;* See the License for the specific language governing permissions and&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;* limitations under the License.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;*/&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;package com.apps.experiment;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;import java.util.ArrayList;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;import android.app.Activity;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;import android.content.ContentProviderOperation;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;import android.database.Cursor;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;import android.os.Bundle;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;import android.provider.ContactsContract;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;public class Main extends Activity&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;// For the sake of keeping the example simply, the query operation are done&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;// &amp;nbsp; in onCreate. Normally query operations should NOT be done in onCreate,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;// &amp;nbsp; but in a dedicated thread.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;@Override&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;public void onCreate(Bundle savedInstanceState)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;super.onCreate(savedInstanceState);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;setContentView(R.layout.main);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;// For performance reasons, normally you would define a projection over the columns you need.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Cursor cur = managedQuery(ContactsContract.Data.CONTENT_URI, null, null, null, null);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if ( (null == cur) || (!cur.moveToFirst()) )&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;return;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;// For keeping the example simple we consider only the first contact.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;// &amp;nbsp; Normally you would iterate over all contacts&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;String raw_contact_id = cur.getString(cur.getColumnIndex(ContactsContract.Data.RAW_CONTACT_ID));&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;String where = ContactsContract.Data.RAW_CONTACT_ID + &quot; = ? AND &quot; +&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ContactsContract.Data.MIMETYPE + &quot; = ? AND &quot; +&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String.valueOf(ContactsContract.CommonDataKinds.Email.TYPE) + &quot; = ?&quot;;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;String[] params = new String[]{raw_contact_id,&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String.valueOf(ContactsContract.CommonDataKinds.Email.TYPE_HOME)};&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;// For performance reasons, normally you would define a projection over the columns you need.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Cursor emailCur = managedQuery(ContactsContract.Data.CONTENT_URI, null, where, params, null);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;ArrayList&amp;lt;ContentProviderOperation&amp;gt; ops = new ArrayList&amp;lt;ContentProviderOperation&amp;gt;();&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;// If nothing has been found, no HOME email has been specified yet.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;// Insert the HOME email to the contact.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if ( (null == emailCur) || (!emailCur.moveToFirst()) )&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.withValue(ContactsContract.Data.RAW_CONTACT_ID, raw_contact_id)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.withValue(ContactsContract.CommonDataKinds.Email.DATA, &quot;somebody@gmail.com&quot;)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.withValue(ContactsContract.CommonDataKinds.Email.TYPE, ContactsContract.CommonDataKinds.Email.TYPE_HOME)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.build());&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;else&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;{ // Otherwise update the existing HOME email address.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.withSelection(where, params)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.withValue(ContactsContract.CommonDataKinds.Email.DATA, &quot;somebody@gmail.com&quot;)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.build());&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;try&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;catch (Exception e)&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;// Handle your exception here.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;&lt;div style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;Other related blogs&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Android contacts: CONTACT_ID vs RAW_CONTACT_ID&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;a href=&quot;http://android-contact-id-vs-raw-contact-id.blogspot.com/&quot;&gt;http://android-contact-id-vs-raw-contact-id.blogspot.com/&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: xx-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Geo-Filtered Assistant&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;a href=&quot;http://geo-filtered-assistant.blogspot.com/&quot;&gt;http://geo-filtered-assistant.blogspot.com/&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;b&gt;Support information sharing&lt;/b&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;To support free information sharing please visit one of our sponsors below.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://email-addresses-in-android-contacts.blogspot.com/feeds/4127844235182307807/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://email-addresses-in-android-contacts.blogspot.com/2011/04/how-to-insert-and-update-email.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4228853134948674154/posts/default/4127844235182307807'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4228853134948674154/posts/default/4127844235182307807'/><link rel='alternate' type='text/html' href='http://email-addresses-in-android-contacts.blogspot.com/2011/04/how-to-insert-and-update-email.html' title='How to insert and update email addresses in Android contacts'/><author><name>Ali Chousein</name><uri>http://www.blogger.com/profile/15925871269074773713</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZkW3e0y_5wV6XjWVRv1SFMaLy2adh8cu75E99Z3AY2M5Tjd9l4_lkSpSry7fV59BYbyetUqgsWBAz7PB_KaNa3AqKMUtd2okIoF8y0JgaMNK9cXyx_pcKoNnL2ZxX_A/s220/chousein.png'/></author><thr:total>2</thr:total></entry></feed>