小编Ars*_*lan的帖子

如何在Android中检索联系人姓名和电话号码

我正在尝试检索联系人列表,其中包含姓名和电话号码.我尝试以下代码:

 // Get a cursor over every contact.
    Cursor cursor = getContentResolver().query(People.CONTENT_URI, 
                                               null, null, null, null); 
    // Let the activity manage the cursor lifecycle.
    startManagingCursor(cursor);
    // Use the convenience properties to get the index of the columns
    int nameIdx = cursor.getColumnIndexOrThrow(People.NAME); 

    int phoneIdx = cursor. getColumnIndexOrThrow(People.NUMBER);
    String[] result = new String[cursor.getCount()];
    if (cursor.moveToFirst())
      do { 
        // Extract the name.
        String name = cursor.getString(nameIdx);
        // Extract the phone number.
        String phone = cursor.getString(phoneIdx);
        result[cursor.getPosition()] = name + "-" +" "+  phone; …
Run Code Online (Sandbox Code Playgroud)

android contacts

9
推荐指数
2
解决办法
3万
查看次数

标签 统计

android ×1

contacts ×1