标签:
//联系人信息 public void bt5_OnClick(View v) { //得到调用者 ContentResolver contentResolver=getContentResolver(); //准备URI // ContactsContract.Contacts.CONTENT_URI; //调用提供者 Cursor cursor=contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); //遍历数据集合 if (cursor!=null) { while (cursor.moveToNext()) { long id=cursor.getLong(cursor.getColumnIndex(ContactsContract.Contacts._ID)); String sName=cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); Log.e("TAG","id="+id+"Name="+sName); //读这个联系人的电话信息 Cursor c= getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=?", new String[]{id + ""}, null); if (c!=null) { while (c.moveToNext()) { //读电话 long Pid=c.getLong(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID)); String number=c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); Log.e("TAG",sName+"电话号码="+number+"id="+Pid); } c.close(); } } Toast.makeText(MainActivity.this, "联系人的数量="+cursor.getCount(), Toast.LENGTH_SHORT).show(); }else { Toast.makeText(MainActivity.this, "未查到联系人的信息", Toast.LENGTH_SHORT).show(); } }
标签:
原文地址:http://www.cnblogs.com/jiang2538406936/p/5676762.html