簡體   English   中英

通過意圖將圖像傳遞給默認聯系人活動

[英]Pass image via intent to default contacts activity

我需要一些將照片插入通訊錄的幫助,據我研究,我發現我們可以通過兩種方式在手機中插入通訊錄,一種是啟動手機的通訊錄活動,另一種是將值直接插入到手機中。電話,我使用的是第一種方法,我們必須啟動意圖,當我們啟動意圖時,我沒有任何添加圖像的解決方案,我可以選擇添加其他較小的細節,例如名稱,工作地點等。第二種方法是,它不會讓我們知道聯系人是否已添加,這可能會導致錯誤,並且可能會創建重復的聯系人。 你建議我能做什么? 我到目前為止一直在做的是

     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 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);

將位圖轉換為byteArray的邏輯是

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM