Android阅读联系人号码

时间:2010-12-10 03:04:38

标签: android android-contacts

我正在尝试这个

    Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null,
            null, null, null);
    Cursor cursor1 = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
            null, null, null);

    int nameIdx = cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME);
    int phoneIdx = cursor1.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER);

    if (cursor.moveToFirst())
        do {
            // Extract the name.
            String name = cursor.getString(nameIdx);
            // Extract the phone number.
            String phone = cursor.getString(phoneIdx);
            Log.i("ContentProvider", name);
            Log.i("ContentProvider", phone);
        } while (cursor.moveToNext());

我能够读取姓名但数字我收到错误

alt text

1 个答案:

答案 0 :(得分:3)

完成本教程,这可以帮助您解决问题

链接如下: http://developer.android.com/resources/samples/ContactManager/index.html