0

我正在尝试从 DATA 表中获取特定 RAW_CONTACT_ID 的数据,但我得到的只是空查询输出。逻辑似乎很简单,但我就是不知道为什么会这样。谷歌搜索但找不到类似的东西。

 public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);    

String where = RawContacts.DELETED + "<> 0 and " + RawContacts.ACCOUNT_TYPE + "=?";
Cursor c = getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI, 
                                        new String[] {RawContacts._ID,
                                                      RawContacts.ACCOUNT_NAME,
                                                      RawContacts.ACCOUNT_TYPE,
                                                      RawContacts.DISPLAY_NAME_PRIMARY
                                                      }, 
                                        where,
                                        new String[] {"Local Phone Account"}, 
                                        null);
int i = 0;
if (c.getCount() > 0) {
    while (c.moveToNext()  && i < 10) {
        i = i + 1;
        // get the id from RawContacts cursor
        String rawID = c.getString(c.getColumnIndex(RawContacts._ID));
        tv.append("searching RawID " + rawID + "\n" +
                    "account name: " + c.getString((c.getColumnIndex(RawContacts.ACCOUNT_NAME))) + "\n" + 
                    "account type: " + c.getString(c.getColumnIndex(RawContacts.ACCOUNT_TYPE)) + "\n" +
                    "display name: " + c.getString(c.getColumnIndex(RawContacts.DISPLAY_NAME_PRIMARY)) + "\n"
                    );

        // create a cursor from Data table for the RawContacts ID    
        Cursor cur = getContentResolver().query(Data.CONTENT_URI, 
                                                new String[] {Data._ID}, 
                                                Data.RAW_CONTACT_ID + "=?", 
                                                new String[] {String.valueOf(rawID)}, 
                                                null
                                                );

        tv.append("found " + cur.getCount() + " matches for id " + String.valueOf(rawID) + "\n");
        cur.close();
        }
}
setContentView(tv);
}
4

0 回答 0