i want to pick a contact with it's number from my contacts list. i read a lot of solutions and research for couple weeks but all of articles didn't work properly. some codes like following:
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
// and in activityresult:
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.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
tv1.setText(name);
}
}
or this code for getting all contacts but i cant have the number of contacts:
String[] contacts = new String[] {People.NAME, People.NUMBER};
Uri contentUri = People.CONTENT_URI;
Cursor cursor = managedQuery(contentUri, contacts, null, null, null);
String textContacts = "";
if (cursor.moveToFirst()) {
String myname = null;
String mynumber = null;
do {
textContacts = textContacts + cursor.getString(cursor.getColumnIndex(People.NAME)) + " : " + cursor.getString(cursor.getColumnIndex(People.NUMBER)) + "\n";
} while (cursor.moveToNext());
tv1.setText(textContacts);
}
can anyone help me plz? my android is 2.3.3
try following code,
This may help you:
This will work check it out
If you want to pick a contact from contact list on click or focus event then copy this code and paste in Your activity.
FOCUS EVENT OF EDIT TEXT:
A FUNCTION TO GET THE CONTACT NAME AND PHONE NO IS :
}
This code will work for mobile number contacts, not for email or something. i found this code simplest. let me know if there is any problem.
start activity with pick intent on phone data type:
Now set onAcitivityResult();
Without manifest or run time permissions you can try this.
To pickup the name and contact number both from contacts app. By this code the contact app will also show the number below the contact name.
The code is to pick only single name and number from contacts app.
And here is
onActivityResult
method's code