1

我有一个联系人列表,其中有多个姓名具有相同的电子邮件 ID。如何修改下面的代码,以便我只获得具有不同电子邮件 ID 的姓名。

public ArrayList<String> getNameEmailDetails(){
        ArrayList<String> names = new ArrayList<String>();
        ContentResolver cr = getContentResolver();
        Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
        if (cur.getCount() > 0) {
            while (cur.moveToNext()) {
                String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
                Cursor cur1 = cr.query( 
                        ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,
                        ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", 
                                new String[]{id}, null); 
                while (cur1.moveToNext()) { 
                    //to get the contact names
                    String name=cur1.getString(cur1.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
                    Log.e("Name :", name);
                    String email = cur1.getString(cur1.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
                    Log.e("Email", email);
                    if(email!=null){
                        names.add(name);
                    }
                } 
                cur1.close();
            }
        }
        return names;
    }
4

1 回答 1

1

sqlite中有一个游标来获取不同的值,true的使用只给出不同的值

Cursor cursor = sqliteDB.query(true,"window",new String[]{"MediaType","_id",TAG_DATA_OR_LOCATION}, null, null,"DataOrLocation", null, null, null);

公共游标查询(布尔不同,字符串表,字符串 [] 列,字符串选择,字符串 [] selectionArgs,字符串 groupBy,字符串有,字符串 orderBy,字符串限制)

于 2013-03-21T10:40:41.663 回答