我用以下代码实现在屏幕上打印contactId
和telephone number
。
我在网上找了这段代码,有些语句还是不明白:
ContentResolver solver = getContentResolver();
String mess="";
Cursor cursor = solver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (cursor.moveToNext()){
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
mess = mess + "ID: "+contactId+"\n";
Cursor phones = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, null, null);
while (phones.moveToNext()) {
String phoneNumber = phones.getString(phones.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER));
mess = mess + phoneNumber + "\n";
}
}
这个语句我不知道什么意思:
Cursor phones = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, null, null);
就像Android 开发中第三个参数:
selection : A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given URI.
所以,按照上面的定义,CONTACT_ID意思是一个行。因为filter which row to return
。
下面这一行:
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
CONTACT_ID看上去意思是一个列。
对这个问题我很疑惑,谁可以帮我指点一二呢?谢谢!