-1

I am following this library to add contact picker https://github.com/codinguser/android_contact_picker, and I am able to get numbers successfully from adding to my EditTextBox but, I want to add multiple contacts selected from contact and add only number in particular EditTextView this is my contact picker activity, I am stuck about that where to add adapter to complete that, any help?:

public class ContactsPickerActivity extends AppCompatActivity implements OnContactSelectedListener {
public static final String SELECTED_CONTACT_ID  = "contact_id";
public static final String KEY_PHONE_NUMBER     = "phone_number";
public static final String KEY_CONTACT_NAME     = "contact_name";


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_contacts);

    FragmentManager         fragmentManager     = this.getSupportFragmentManager();
    FragmentTransaction     fragmentTransaction = fragmentManager.beginTransaction();
    ContactsListFragment fragment           = new ContactsListFragment();

    fragmentTransaction.replace(R.id.fragment_container, fragment);
    fragmentTransaction.commit();

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle("Select contact");
    }
}


@Override
public void onContactNameSelected(long contactId) {
    /* Now that we know which Contact was selected we can go to the details fragment */

    Fragment    detailsFragment = new ContactDetailsFragment();
    Bundle      args            = new Bundle();
    args.putLong(ContactsPickerActivity.SELECTED_CONTACT_ID, contactId);
    detailsFragment.setArguments(args);
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    // Replace whatever is in the fragment_container view with this fragment,
    // and add the transaction to the back stack
    transaction.replace(R.id.fragment_container, detailsFragment);

    transaction.addToBackStack(null);
    // Commit the transaction
    transaction.commit();
}

/**
 * Callback when the contact number is selected from the contact details view 
 * Sets the activity result with the contact information and finishes
 */
@Override
public void onContactNumberSelected(String contactNumber, String contactName) {
    Intent intent = new Intent();
    intent.putExtra(KEY_PHONE_NUMBER, contactNumber);
    intent.putExtra(KEY_CONTACT_NAME, contactName);

    setResult(RESULT_OK, intent);
    finish();
}
Flutterian
  • 1,761
  • 1
  • 21
  • 47
subhash
  • 41
  • 1
  • 7

1 Answers1

0

Try this library https://github.com/1gravity/Android-ContactPicker it will help you to pick multiple contacts. You will get selected contacts in onActivityResult() method, from here you can display it in editText.

Manoj j
  • 152
  • 4
  • 15
  • Manoj previously i am used this library only but here am able to get name only but my requirement is for number not for contact i need to display contact numbers instead of name so how can do this . – subhash Nov 24 '17 at 06:15
  • yes, you can display numbers too. putExtra(ContactPickerActivity.EXTRA_CONTACT_DESCRIPTION, ContactDescription.ADDRESS.name()) in this line instead of using ADDRESS.name() use PHONE.name() – Manoj j Nov 24 '17 at 06:36
  • its not working still is coming in name what should i do? – subhash Nov 24 '17 at 08:04
  • can you please give me any suggestion on that. – subhash Nov 24 '17 at 09:09
  • Manoj when i select the contact number and showing in textviw its display contact name i need contact number. – subhash Nov 24 '17 at 09:18
  • in the list, it will display both name and contact number, after selecting you can get the numbers in onActivityResult(). Loop through the selected contacts and use contact.getPhone() method. You can find a demo on the GitHub page only. – Manoj j Nov 24 '17 at 10:02
  • if (contacts != null && !contacts.isEmpty()) { result.append("\n" + ""); for (Contact contact : contacts) { populateContact(result, contact, ""); } } Can you please corrent me on that. – subhash Nov 24 '17 at 10:29
  • contact.getPhone() is a integer type please correct me. – subhash Nov 24 '17 at 10:30
  • 1
    This lib does not give support to sdk 28+ – Roni Castro Oct 09 '18 at 21:33