读取联系人信息

读取联系人信息,用了android自带的PEOPLE.CONTENT_URI,provider.Contacts.CONTENT_URI都不好用,获取不到联系人号码,随后找到Phones.CONTENT_URI才顺利显示。
ContentResolver contentResolver = this.getContentResolver();

        Cursor cursor = contentResolver.query(Phones.CONTENT_URI, null, null,
            null, null);

        Log.e("ray", "" + cursor.getCount());

        if (cursor.moveToFirst())
        {

            long start = System.currentTimeMillis();

            do
            {

                int nameIndex = cursor.getColumnIndex(Phones.DISPLAY_NAME);

                int numberIndex = cursor.getColumnIndex(Phones.NUMBER);

                String contactName = cursor.getString(nameIndex);

                String contactNumber = cursor.getString(numberIndex);

                Log.e("ray", "contactName" + contactName + "contactNumber"
                    + contactNumber);

            }
            while (cursor.moveToNext());

            long end = System.currentTimeMillis();

            Log.e("ray", "time  " + (end - start));
        }
        cursor.close();

你可能感兴趣的:(Android)