I am making an app that accesses the mobile phone contacts and shows them, but I want to show them organized by type, be it Person, Work, Home, Work Fax, etc.
In this way I get them all and it works perfectly but the problem is that I have not found a way to obtain them for the aforementioned types.
Here I leave the code of what I have done, Thank you very much
TextView contactos_home = (TextView) findViewById(R.id.contactos_home);
Cursor cursor = getContentResolver().query( ContactsContract.Data.CONTENT_URI, new String[] {ContactsContract.Data.DISPLAY_NAME}, null, null, null);
while (cursor.moveToNext()){
String contactos = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
contactos_home.append(contactos);
contactos_home.append("\n");
}
The third attribute allows filtering. More than one sort item can be added by separating the items with commas. Here is an example:
You should change the attributes in the example to your attributes.
The last parameter is the ordering (sortOrder) based on that you can get the contacts, for example if you want an ordering by person name define
ContactsContract.Data.DISPLAY_NAME
, it is important that the second parameter:To obtain specific data you must review the tables and define based on what data you want to order your results:
Answering my question.
Here I leave the table with the constant of the main types of contacts
To get a specific type you just have to change the comparison in the variable (selectClause) (ContactsContract.CommonDataKinds.Phone.TYPE + "=' 2 ')