我需要一点帮助。我只需要在此联系人列表中获取 Mobile 类型的号码。
使用此代码,我提取了所有数字,而我只需要使用移动类型..并将它们显示在列表中。帮助我,并提前感谢!
代码:
void ReadContacts(String sort) {
final Uri uri = Phone.CONTENT_URI;
final String[] projection = new String[] {
Contacts._ID,
Phone.NUMBER,
Contacts.DISPLAY_NAME,
Phone.TYPE
};
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";
String[] selectionArgs = null;
final String sortOrder = Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
m_curContacts = managedQuery(uri, projection, selection, selectionArgs, sortOrder);
String[] fields = new String[] {Contacts.DISPLAY_NAME, Phone.NUMBER};
m_slvAdapter = new SimpleCursorAdapter(this,R.layout.simple_list_item_mio,m_curContacts,fields,
new int[] {R.id.text1, R.id.text2});
m_slvAdapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
Log.d(LOG_TAG, "runQuery constraint:"+constraint);
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'" +
" AND "+ Contacts.DISPLAY_NAME + " LIKE '%"+constraint+"%'";
String[] selectionArgs = null;//new String[]{"'1'"};//, };
Cursor cur = managedQuery(uri, projection, selection, selectionArgs, sortOrder);
return cur;
}
});
ps:Phone.TYPE 手机是int 2。