Course Content

If you are facing any issue in playing video please use Firefox browser.

Course Content

Description

Contact Application in Android

How to solve ?

  • Create an Activity
  • Take a Button
  • Use Button Click Listener
  • Use Intent (Implicit Intent)
  • Use native content provider

Firstly we will open Android studio and then we will start a new Android studio project named 'ImplicitIntent'. And Company domain as 'com.example'.

We'll save Activity name as 'MainActivity' and Layout name as 'main' and then click on Finish.

Now our project will be created, and very first we have to create the interface. But before that we will open our manifest  'AndroidManifest.xml' file and add permission here because we want to work with native content provider,

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

Now we will design layout for this project, for that we will open 'main.xml', here we have simply added a button, and specified text, ID, height, gravity, and width.

<Button

android:layout_width=""wrap_content""

android:layout_height=""wrap_content""

android:layout_gravity=""center_horizontal""

android:text=""View Contacts""

android:id=""@+id/ViewContacts""

</Button>

Now we will open our main Java file in which will see that the code is default generated, now we will code here to access native content provider, for that we will first design a method,

private void ViewContacts()

{

try

{

Button ViewContacts=(Button)findViewById(R.id.ViewContacts);

 

Now we will design a Click Listener for this button,

viewContacts.setOnClickListener(new onClickListener())

{

public void onClick(View v)

{

Intent contacts=new Intent();

contacts.setAction(Intent.ACTION_VIEW);

contacts.setData(People.CONTENT_URI);

startActivity(contacts);

}

}};

 

Now we will call this method,

ViewContacts();

Now we will execute this code and see how it works, when our application runs we will see a button named 'View Contacts' and when we click on that button we will be redirected to our Phone's contact list.

FAQs

Recommended Courses

Share With Friend

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

Download The Apps

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