选择存储在手机内存中的所有联系人只有android

时间:2013-08-09 06:04:28

标签: android contact

我需要从手机内存中取消联系,而不是从SIM卡中取出。我使用以下代码,但它从sim和手机中获取所有联系人。请帮帮我。

这是我的代码

private void getcontacts(){
         ContentResolver cr = getContentResolver();
          ArrayList<String> contactsBuffer = new ArrayList<String>();
            Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
                    null, null, null, null);
            if (cur.getCount() > 0) {
                while (cur.moveToNext()) {
                      String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
                      String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                      if (Integer.parseInt(cur.getString(
                            cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                         Cursor pCur = cr.query(
                                   ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                                   null,
                                   ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
                                   new String[]{id}, null);
                         while (pCur.moveToNext()) {
                             String phoneNo = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                             //Toast.makeText(MainActivity.this, "Name: " + name + ", Phone No: " + phoneNo, Toast.LENGTH_SHORT).show();
                             contactsBuffer.add( name +" "+phoneNo);
                         }
                        pCur.close();
                    }
                }
            }


    }

0 个答案:

没有答案