android系统1.6中 读取联系人:
cursor = cr.query(People.CONTENT_URI, null, null, null, "name desc"); //取得联系人名次name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME)); //取得联系人id String id = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup._ID)); //构造查询条件,根据联系人id为条件,查询手机号字段的信息 String selection = ContactsContract.CommonDataKinds.Phone.CONTACT_ID+" = ? and "+ContactsContract.CommonDataKinds.Phone.TYPE+" = ?"; String[] selectionArgs = {id,"2"}; cursorSingle = cr.query(Uri.parse("content://com.android.contacts/data/phones"), new String[]{"data1"}, selection, selectionArgs, null); cursorSingle.moveToNext(); mobile = cursorSingle.getString(0);
获取联系人名称和手机号
cursor.moveToNext(); name = cursor.getString(cursor.getColumnIndex(Phones.NAME)); mobile = cursor.getString(cursor.getColumnIndex(Phones.NUMBER));
android系统2.2中 读取联系人,此时只是取到名称以及联系人的id,还要根据id获取手机号码
cursor = cr.query("content://com.android.contacts/contacts", null, null, null, "sort_key asc");
获取联系人名称和手机号码
//取得联系人名次 name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME)); //取得联系人id String id = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup._ID)); //构造查询条件,根据联系人id为条件,查询手机号字段的信息 String selection = ContactsContract.CommonDataKinds.Phone.CONTACT_ID+" = ? and "+ContactsContract.CommonDataKinds.Phone.TYPE+" = ?"; String[] selectionArgs = {id,"2"}; cursorSingle = cr.query(Uri.parse("content://com.android.contacts/data/phones"), new String[]{"data1"}, selection, selectionArgs, null); cursorSingle.moveToNext(); mobile = cursorSingle.getString(0);