How to pick contact into edittext using fragment

234 Views Asked by At

I work with same app I pick my contacts using activities class and it work perfectly now I add same tablayout and fragment I do every possible methods to be solved Her is some code

public void pickContact(View v)
{
    Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,
        ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
    startActivityForResult(contactPickerIntent, RESULT_PICK_CONTACT);
}

It's filld after I build and onclick pickContact button the app stopped working

2

There are 2 best solutions below

1
kundan kamal On

You need to run time permission first and then.You use activity context to call startActivityForResult().

public void pickContact(View v)
{
    Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,
        ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
    getActivity().startActivityForResult(contactPickerIntent, RESULT_PICK_CONTACT);
}
0
Syed Danish Haider On

i am using this library for contact picker

[Multiple contact picker][1]https://github.com/broakenmedia/MultiContactPicker