如何从电话联系人中获取一组联系人列表

时间:2013-04-01 08:00:44

标签: java android

btngal.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent i=new Intent(Intent.ACTION_PICK,android.provider.ContactsContract.Contacts.CONTENT_GROUP_URI);
                startActivityForResult(i,0);        
            }
        }); 

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_CANCELED) {
            if (requestCode == 0) {
                Uri selectContact=data.getData();
                String[] filePathColumn={Contacts.CONTENT_URI.toString()};
                Cursor cursor = getContentResolver().query(selectContact,
                        filePathColumn, null, null, null);
                cursor.moveToFirst();

                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
             filePath = cursor.getString(columnIndex);
                cursor.close();

            }
        }

    }

执行此操作时,我收到以下错误:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.PICK dat=content://com.android.contacts/contacts/group }

1 个答案:

答案 0 :(得分:0)

要从原生Android应用程序中读取联系人,您需要权限,例如manifest.xml

<uses-permission android:name="android.permission.READ_CONTACTS"/>

确保你有那个。