That should work. The idea is to join a search in a data table, but use material from CommonDataKinds. This is done where the sentence ... Data.MIMETYPE == CommonDataKinds.Relation.CONTENT_ITEM_TYPE
. This will give you a line with all Relation materials.
import android.database.Cursor; import android.net.Uri; import android.provider.ContactsContract.CommonDataKinds.Relation; import android.provider.ContactsContract.Data; import android.util.Log; ... public void logCatTheRelation(long contactId){ Uri uri = Data.CONTENT_URI; String where = String.format( "%s = ? AND %s = ?", Data.MIMETYPE, Relation.CONTACT_ID); String[] whereParams = new String[] { Relation.CONTENT_ITEM_TYPE, Long.toString(contactId), }; String[] selectColumns = new String[]{ Relation.NAME, // add additional columns here }; Cursor relationCursor = this.getContentResolver().query( uri, selectColumns, where, whereParams, null); try{ if (relationCursor.moveToFirst()) { Log.d("gizm0", relationCursor.getString( relationCursor.getColumnIndex(Relation.NAME))); } Log.d("gizm0", "sadly no relation ... "); }finally{ relationCursor.close(); } }
giZm0 source share