i am using following code in order to fetch contacts from Phone
i am getting names but not number , help me to find out other fields of contacts.
public class DialActivity extends Activity {
private ListView mContactList;
public String[] fields;
public Cursor cursor;
public boolean mShowInvisible;
public Uri uri;
public String[] projection;
public String[] selectionArgs;
public String selection;
public String sortOrder;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mContactList = (ListView) findViewById(R.id.ListView01);
// Populate the contact list
populateContactList();
}
/**
* Populate the contact list based on account currently selected in the account spinner.
*/
private void populateContactList() {
// Build adapter with contact entries
Cursor cursor = getContacts();
String[] fields = new String[] {
ContactsContract.Data.DISPLAY_NAME
};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.listrow, cursor,
fields, new int[] {R.id.TextView01});
mContactList.setAdapter(adapter);
}
/**
* Obtains the contact list for the currently selected account.
*
* @return A cursor for for accessing the contact list.
*/
private Cursor getContacts()
{
// Run query
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME
};
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" +
(mShowInvisible ? "0" : "1") + "'";
String[] selectionArgs = null;
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
return managedQuery(uri, projection, selection, selectionArgs, sortOrder);
}
}
In the above code i am using a custom ListRow layout and showing the contact name in each row, but want to populate a list which has names and corresponding number so that i can make a call on those number by clicking on that listItem. I know how to make call but i am not having the numbers.
ContactsContract.Contacts doesn’t contain the phone number but you have the id of the contacts so you can now query
ContactsContract.Datato get the phone number. A sample query can be found at the documentation: http://developer.android.com/reference/android/provider/ContactsContract.Data.html