Rabindra nath Nandi
Rabindra nath Nandi

Reputation: 1

How to call the Contacts application in android phone

I need to show the contact list and do not want to make a contact list by a program. I want to call the Contacts application that is available in all android phone. I already know the package name is com.android.contacts.But I do not know the class names of this package.

Anybody can help me, please.

Upvotes: 0

Views: 5494

Answers (1)

ObAt
ObAt

Reputation: 2387

Use this code:

void showContacts()
{
    Intent i = new Intent();
    i.setComponent(new ComponentName("com.android.contacts", "com.android.contacts.DialtactsContactsEntryActivity"));
    i.setAction("android.intent.action.MAIN");
    i.addCategory("android.intent.category.LAUNCHER");
    i.addCategory("android.intent.category.DEFAULT");
    startActivity(i);
}

Source: Android Launching Contacts Application

Or use this code to get all the contacts without lauching a new intent:

Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);

@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
  super.onActivityResult(reqCode, resultCode, data);

  switch (reqCode) {
    case (PICK_CONTACT) :
      if (resultCode == Activity.RESULT_OK) {
        Uri contactData = data.getData();
        Cursor c =  managedQuery(contactData, null, null, null, null);
        if (c.moveToFirst()) {
          String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
          // TODO Whatever you want to do with the selected contact name.
        }
      }
      break;
  }
}

Also don't forget to set this permission:

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

Source: How to call Android contacts list?

Upvotes: 1

Related Questions