1

嗨,我正在尝试使用预先填充的数据调用创建联系人表单并能够输入基本详细信息。我可以输入姓名、电子邮件、电话号码,但我无法加载联系人的缩略图。代码的相关部分是:

// Creates a new intent for sending to the device's contacts application
        Intent insertIntent = new Intent(ContactsContract.Intents.Insert.ACTION);

        // Sets the MIME type to the one expected by the insertion activity
        insertIntent.setType(ContactsContract.RawContacts.CONTENT_TYPE);

        /**
         * Added this extra for 4.0 device as on save the onActivityResult was
         * not getting invoked rather a new activity was invoked
         **/
        String INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED = "finishActivityOnSaveCompleted";
        insertIntent.putExtra(INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED,
                true);
        // Sets the new contact name
        insertIntent.putExtra(ContactsContract.Intents.Insert.NAME,
                "name");

        insertIntent.putExtra(ContactsContract.Intents.Insert.PHONE,
                (Utility.formatPhoneNumber(mCellNumber)));
        insertIntent.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE,
                Phone.TYPE_MOBILE);
        insertIntent.putExtra(ContactsContract.Intents.Insert.SECONDARY_PHONE,
                (Utility.formatPhoneNumber(mOfficeNumber)));
        insertIntent.putExtra(
                ContactsContract.Intents.Insert.SECONDARY_PHONE_TYPE,
                Phone.TYPE_WORK);

        **insertIntent.putExtra(
                ContactsContract.Intents.ATTACH_IMAGE,getPhotoUrl());**

        // Send out the intent to start the device's contacts app in its add
        // contact activity.
        startActivityForResult(insertIntent,
                REQUEST_CODE_ADD_NEW_CONTACT);

关于如何做到这一点的任何指针。谢谢 !

4

1 回答 1

0

我认为使用插入意图是实现这一目标的关键。

您正在使用

ContactsContract.Intents.ATTACH_IMAGE

这解释了这一点,

Starts an Activity that lets the user pick a contact to attach an image to. After picking the contact it launches the image cropper in face detection mode.

Constant Value: "com.android.contacts.action.ATTACH_IMAGE"

这是一个完整的示例,解释了您要查找的内容。

使用联系人提供程序以编程方式添加带照片的联系人

于 2012-12-14T07:45:20.853 回答