Course Content

Course Content


Android Content Provider Example

In this Video tutorial we will learn about Android Content Provider Example in Hindi. First of all we will create an application named 'ContactsAdd', and then inside its 'AndroidManifest.xml' file, we will add two permissions,

<uses-permission android:name=""android.permission.READ_CONTACTS""/>

<uses-permission android:name=""android.permission.WRITE_CONTACTS""/>


After that we will design the application's layout in our 'activity_main.xml', for that we will be using five EditTexts for name, mobile phone, home phone, work email, and home email. Also we will use two buttons, one for Add contact, and other for Contact list.

Now we will open our '' file from 'java' folder, and now we have to write code for Adding Contact using content provider.

First of all we have to create one Listener for a button,

OnClickListener addOnClickListener=new OnClickListener ()



public void onClick (View v)


EditText etName=(EditText) findViewById(;

EditText etMobile=(EditText) findViewById(;

EditText etHomePhone=(EditText) findViewById(;

EditText etHomeEmail=(EditText) findViewById(;

EditText etWorkEmail=(EditText) findViewById(;


Now we will use an array list,

ArrayList<ContentProviderOperation> opa=new ArrayList<ContentProviderOperation>();

int rawContactID=ops.size();


Now whatever options we want to provide we will use it with 'ops.add(_);' ,






Similarly we have to add all the contents which we want,


.withValueBackReference(ContactContract.Data.RAW_CONTACT, rawContactID)

.withValue(ContactContract.Data.MIMETYPE, StructureName.CONTENT_ITEM_TYPE)

.withValue(StructureName.DISPLAY_NAME, etName.getText().toString()




 After that we need to define all the different contents which we used in our application like phone number, name, e-mail, work e-mail, etc...

So after that we will now generator toast notification when any contact is added,

Toast.makeText(getBaseContext(), ""Contact is successfully added"", Toast.LENGTH_SHORT).show();

Now to use OnClickListener we will design code for that and than our coding is complete. After that we will execute it.

As soon as we run an application we are displayed five editText and two buttons as we coded, and then when we fill all the details and click on Add Contact button, than our toast notification is also working completely showing ""Contact is successfully added"".


Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
297K+ Downloads
App Download Section Circle 1
4.5 Rating
App Download Section Circle 2
10K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere