public static ContactListAdapter createRcsContactListAdapter(Context context){
  ContentResolver content=context.getContentResolver();
  Cursor cursor=null;
  ConnectionManager apiConnectionManager=ConnectionManager.getInstance();
  MatrixCursor matrix=new MatrixCursor(PROJECTION_PHONE);
  ContactService contactsApi=apiConnectionManager.getContactApi();
  try {
    Set<RcsContact> rcsContacts=contactsApi.getRcsContacts();
    if (rcsContacts != null && !rcsContacts.isEmpty()) {
      Set<ContactId> rcsContactIds=new HashSet<>();
      for (      RcsContact rcsContact : rcsContacts) {
        rcsContactIds.add(rcsContact.getContactId());
      }
      cursor=content.query(Phone.CONTENT_URI,PROJECTION_PHONE,WHERE_CLAUSE_PHONE,null,null);
      if (cursor == null) {
        throw new SQLException("Query failed!");
      }
      Set<ContactId> treatedContactIDs=new HashSet<>();
      int columnIdxId=cursor.getColumnIndexOrThrow(Phone._ID);
      int columIdxLabel=cursor.getColumnIndexOrThrow(Phone.LABEL);
      int columnIdxType=cursor.getColumnIndexOrThrow(Phone.TYPE);
      int columnIdxContactId=cursor.getColumnIndexOrThrow(Phone.CONTACT_ID);
      int columnIdxNumber=cursor.getColumnIndexOrThrow(Phone.NUMBER);
      while (cursor.moveToNext()) {
        String phoneNumber=cursor.getString(columnIdxNumber);
        if (!ContactUtil.isValidContact(phoneNumber)) {
          continue;
        }
        ContactId contact=ContactUtil.formatContact(phoneNumber);
        if (rcsContactIds.contains(contact) && !treatedContactIDs.contains(contact)) {
          matrix.addRow(new Object[]{cursor.getLong(columnIdxId),contact.toString(),cursor.getString(columIdxLabel),cursor.getInt(columnIdxType),cursor.getLong(columnIdxContactId)});
          treatedContactIDs.add(contact);
        }
      }
    }
    return new ContactListAdapter(context,matrix);
  }
 catch (  RcsServiceNotAvailableException e) {
    return null;
  }
catch (  RcsServiceException e) {
    Log.w(LOGTAG,ExceptionUtil.getFullStackTrace(e));
    return null;
  }
 finally {
    if (cursor != null) {
      cursor.close();
    }
  }
}

public static ContactListAdapter createRcsContactListAdapter ( Context context ) { ContentResolver content = context . getContentResolver ( ) ; Cursor cursor = null ; ConnectionManager apiConnectionManager = ConnectionManager . getInstance ( ) ; MatrixCursor matrix = new MatrixCursor ( PROJECTION_PHONE ) ; ContactService contactsApi = apiConnectionManager . getContactApi ( ) ; try { Set < RcsContact > rcsContacts = contactsApi . getRcsContacts ( ) ; if ( rcsContacts != null && ! rcsContacts . isEmpty ( ) ) { Set < ContactId > rcsContactIds = new HashSet < > ( ) ; for ( RcsContact rcsContact : rcsContacts ) { rcsContactIds . add ( rcsContact . getContactId ( ) ) ; } cursor = content . query ( Phone . CONTENT_URI , PROJECTION_PHONE , WHERE_CLAUSE_PHONE , null , null ) ; if ( cursor == null ) { throw new SQLException ( "Query failed!" ) ; } Set < ContactId > treatedContactIDs = new HashSet < > ( ) ; int columnIdxId = cursor . getColumnIndexOrThrow ( Phone . _ID ) ; int columIdxLabel = cursor . getColumnIndexOrThrow ( Phone . LABEL ) ; int columnIdxType = cursor . getColumnIndexOrThrow ( Phone . TYPE ) ; int columnIdxContactId = cursor . getColumnIndexOrThrow ( Phone . CONTACT_ID ) ; int columnIdxNumber = cursor . getColumnIndexOrThrow ( Phone . NUMBER ) ; while ( cursor . moveToNext ( ) ) { String phoneNumber = cursor . getString ( columnIdxNumber ) ; if ( ! ContactUtil . isValidContact ( phoneNumber ) ) { continue ; } ContactId contact = ContactUtil . formatContact ( phoneNumber ) ; if ( rcsContactIds . contains ( contact ) && ! treatedContactIDs . contains ( contact ) ) { matrix . addRow ( new Object [ ] { cursor . getLong ( columnIdxId ) , contact . toString ( ) , cursor . getString ( columIdxLabel ) , cursor . getInt ( columnIdxType ) , cursor . getLong ( columnIdxContactId ) } ) ; treatedContactIDs . add ( contact ) ; } } } return new ContactListAdapter ( context , matrix ) ; } catch ( RcsServiceNotAvailableException e ) { return null ; } catch ( RcsServiceException e ) { Log . w ( LOGTAG , ExceptionUtil . getFullStackTrace ( e ) ) ; return null ; } finally { if ( cursor != null ) { cursor . close ( ) ; } } }
create a contact selector with rcs capable contacts
