Insert New Contact in Android Code Example

android-logoInsert new contact in Android is very easy. Here we will learn how to add a new mobile number  into Android Contacts list programmatically. We will use inbuilt Android classes (ContactsContract, ContentProviderOperation) to add new contacts in Android Contacts List. Below is the code snippet with example and detailed description.


Insert New Contact in Android Code

Step 1:

Add below packages into your java class from where you want to insert new contact into your Contacts List. You can add below packages into your Activity’s class to test the functionality easily. Then you can move the code into any java class.

Step 2:

Now add below function WritePhoneContact() in your java class where you have already added  packages (mentioned in Step 1 above ). Once you added below function into your java class then you have to just call that function to add a new contact into the Android contacts list. To test the functionality, you can add below function (code snippet) into your Activity’s class.

Note: You can find detailed inline code description inside the code.

 Code Description:

In the above function, You can pass arguments as below.

String displayName: Contact’s name (Example John), which need to be add in Android contact list.

String number: Mobile number of the person (Example: 9999999999) which need to be add with the contact (John in our example).

Context cntx: This is nothing but your Activity’s context’s or you can provide your application’s context. Just for the testing purpose, you can call above function from your Activity’s onCreate() function like in Step 3 below.

Step 3:

Call the above mentioned function WritePhoneContact() as below.

That’s it. I hope this small tutorial on how to add new contacts into Android Contacts list will help it it’s best. If you are facing any issue, then please feel free to contact us, we will try to revert you asap.

Note: If you want to invoke the native Contacts Activity for inserting a new contact, then you may follow below code.

You might like to read my Android tutorial “How to read multiple phone numbers in Android Contacts List Programmatically”.


Post By SmrutiRanjan (57 Posts)

Working @ Samsung as a Project Lead for Android Smartphones. I have been blogging since 2008. Previously I was writing articles for other bloggers, but finally I have started my own blog-"Techblogon".I am also an active contributor for the blog-"Gadgets n Gizmos World". Job is my necessity, but blogging is my passion.

Website: → Techblogon


Leave a Reply

Your email address will not be published. Required fields are marked *

8 − = six

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">