Android get a cursor only with contacts that have an email listed >android 2.0

后端 未结 2 1722
春和景丽
春和景丽 2020-11-30 07:08

i have the following code to get contacts from content provider

String[] columns = new String[] {
                ContactsContract.Contacts.DISP         


        
2条回答
  •  悲哀的现实
    2020-11-30 07:40

    I solved this one, here is how its done:

    UPDATE

       String[] PROJECTION = new String[] { ContactsContract.RawContacts._ID,
            ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.PHOTO_ID,
            Email.DATA, ContactsContract.CommonDataKinds.Photo.CONTACT_ID };
    
        String order = " CASE WHEN " + ContactsContract.Contacts.DISPLAY_NAME
            + " NOT LIKE '%@%' THEN 1" + " ELSE 2 END, "
            + ContactsContract.Contacts.DISPLAY_NAME + " COLLATE NOCASE";
        String filter = Email.DATA + " NOT LIKE '' ) GROUP BY ( " + Email.DATA;
    
        return mContent.query(Email.CONTENT_URI,
                          PROJECTION, filter, null, order);
    

提交回复
热议问题