Android从联系人接收号码,电子邮件等

时间:2016-12-17 10:46:42

标签: android contacts

我想访问不同的联系信息,如号码,电子邮件等。 我使用官方Android文档中的代码:

static final int PICK_CONTACT_REQUEST = 1;  // The request code

private void pickContact() {
Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
pickContactIntent.setType(Phone.CONTENT_TYPE); // Show user only contacts w/ phone numbers
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request it is that we're responding to
if (requestCode == PICK_CONTACT_REQUEST) {
    // Make sure the request was successful
    if (resultCode == RESULT_OK) {
        // Get the URI that points to the selected contact
        Uri contactUri = data.getData();

        String[] projection = {Phone.NUMBER};

        Cursor cursor = getContentResolver()
                .query(contactUri, projection, null, null, null);
        cursor.moveToFirst();

        // Retrieve the phone number from the NUMBER column
        int column = cursor.getColumnIndex(Phone.NUMBER);
        String number = cursor.getString(column);

        // Do something with the phone number...
    }
}
}

问题是,我只能访问电话号码和姓名,其他数据不能。我可以将pickContactIntent.setType更改为电子邮件内容类型,但我只能访问电子邮件...在这种情况下如何访问不同类型的数据?

0 个答案:

没有答案