Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Firstly use ContentProviderOperation's way to insert a new Contact.</p> <pre><code>final ArrayList&lt;ContentProviderOperation&gt; ops = new ArrayList&lt;ContentProviderOperation&gt;(); ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI) .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null) .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null) .build()); Bitmap bmp = YCardImageLoader.getInstance().getBitmapByCache(mTask.getImageUrl()); if (bmp != null ) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(CompressFormat.JPEG, 100, stream); byte[] bytes = stream.toByteArray(); ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) .withValueBackReference(Data.RAW_CONTACT_ID, 0) .withValue(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE) .withValue(Photo.PHOTO, bytes) .build()); } ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) .withValueBackReference(Data.RAW_CONTACT_ID, 0) .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE) .withValue(StructuredName.DISPLAY_NAME, mContact.getName()) .build()); ContentProviderResult[] result = SaveToPbkActivity.this.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); </code></pre> <p>Then get result uri as the ACTION_EDIT uri, put other extras, startActivityForResult(intent, REQUEST_INSERT_CONTACT).</p> <pre><code> Intent editIntent = new Intent(Intent.ACTION_EDIT); uri = result[0].uri; editIntent.setDataAndType(uri, Contacts.CONTENT_ITEM_TYPE); editIntent.putExtra("finishActivityOnSaveCompleted", true); putExtras(editIntent, null); startActivityForResult(editIntent, REQUEST_INSERT_CONTACT); </code></pre> <p>because we insert first, we will delete it when resultCode != RESULT_OK</p> <pre><code>@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_INSERT_CONTACT) { if (resultCode == RESULT_OK) { //SAVE SUCCESS } else { ContentResolver cr = getContentResolver(); cr.delete(uri, null, null); } } } </code></pre> <p>At last sorry for my english!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload