Download the New LearnVern Android App and enter Lucky Draw to win Free Certificate
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,
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 'MainActivity.java' 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(R.id.et_name);
EditText etMobile=(EditText) findViewById(R.id.et_mobile_phone);
EditText etHomePhone=(EditText) findViewById(R.id.et_home_phone);
EditText etHomeEmail=(EditText) findViewById(R.id.et_home_email);
EditText etWorkEmail=(EditText) findViewById(R.id.et_work_email);
Now we will use an array list,
ArrayList<ContentProviderOperation> opa=new ArrayList<ContentProviderOperation>();
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,
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"".
Have a friend to whom you would want to share this course?