Android receiving number, email, etc. from contact

非 Y 不嫁゛ 提交于 2019-12-25 05:51:10

问题


I want to access different contact information like a number, an email etc. I use code from official Android documentation:

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...
    }
}
}

The problem is, I can only access phone number and name, other data not. I can change pickContactIntent.setType to Email content type, but that I can access only Email... How can I access different kind of data in this case ?

来源:https://stackoverflow.com/questions/41197756/android-receiving-number-email-etc-from-contact

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!