通过 intent 将图像传递给默认联系人 activity

Pass image via intent to default contacts activity

我需要一些关于将照片插入联系人的帮助,据我研究,我发现有两种方法可以在我们的 phone 中插入联系人,一种是启动联系人 activity phone,另一种是直接在 phone 中插入值,我使用的是第一种方法,我们必须在其中启动意图,当我们启动意图时,我没有得到任何解决方案添加图像,我可以选择添加其他次要细节,如姓名、工作地点等。第二种方法的问题是,它不会让我们知道联系人是否已经添加,这可能会导致错误,它可能创建重复的联系人。你建议我能做什么? 我现在所做的是

     Intent contactIntent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT,ContactsContract.Contacts.CONTENT_URI);
            contactIntent.setData(Uri.parse("tel:" +"+91"+mMobile));
            contactIntent.putExtra(ContactsContract.Intents.Insert.NAME, name);
            contactIntent.putExtra(ContactsContract.Intents.Insert.EMAIL, email);
            contactIntent.putExtra(ContactsContract.Intents.Insert.SECONDARY_PHONE, mobileEx);
            startActivity(contactIntent);

要通过 intent for contacts Editor 屏幕传递个人资料图片,您可以执行如下所示的操作

    Intent contactIntent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT,ContactsContract.Contacts.CONTENT_URI);
    contactIntent.setData(Uri.parse("tel:" +"+91"+mMobile));
    contactIntent.putExtra(ContactsContract.Intents.Insert.NAME, name);
    contactIntent.putExtra(ContactsContract.Intents.Insert.EMAIL, email);
    contactIntent.putExtra(ContactsContract.Intents.Insert.SECONDARY_PHONE, mobileEx);

    Bitmap bit = BitmapFactory.decodeResource(getResources(), R.drawable.profile_image);

    ArrayList<ContentValues> data = new ArrayList<ContentValues>();

    ContentValues row = new ContentValues();
    row.put(Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
    row.put(ContactsContract.CommonDataKinds.Photo.PHOTO, bitmapToByteArray(bit));
    data.add(row);
    contactIntent.putParcelableArrayListExtra(Insert.DATA, data);
    startActivity(contactIntent);

bitmap转byteArray的逻辑是

    private byte[] bitmapToByteArray(Bitmap bit) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bit.compress(Bitmap.CompressFormat.PNG, 100, stream);
    byte[] byteArray = stream.toByteArray();
    return byteArray;
}