Add number to contact on Android 2.0

后端 未结 3 1070
感情败类
感情败类 2021-01-19 15:36

Im trying to add a phone number to an already existing contact on a Droid-phone. Doing it at the same time as I create a contact is trivial, as the backreference I supply si

相关标签:
3条回答
  • 2021-01-19 15:37

    I've had a similar problem with email addresses. Here's the solution I used that worked:

    ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
        .withValue(Data.RAW_CONTACT_ID, id)
        .withValue(Email.DATA, value)
        .withValue(Email.MIMETYPE, .Email.CONTENT_ITEM_TYPE)
        .withValue(Email.LABEL, label)
        .withValue(Email.TYPE, Email.TYPE_CUSTOM)
        .build());
    ContentProviderResult[] res = cr.applyBatch(ContactsContract.AUTHORITY, ops);
    

    The same solution should work for telephone numbers.

    0 讨论(0)
  • 2021-01-19 15:40

    These links may provide some help:

    • http://www.higherpass.com/Android/Tutorials/Working-With-Android-Contacts/1/

    • http://developer.android.com/resources/samples/ContactManager/src/com/example/android/contactmanager/ContactAdder.html

    0 讨论(0)
  • 2021-01-19 15:43

    I found an answer. It is not atomic if you want to add several things right away, but hey, who needs stupid atomicity?

    ContentValues values = new ContentValues();
    values.put(Data.RAW_CONTACT_ID, new Integer(contactId).intValue());
    values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
    values.put(Phone.NUMBER, dataValue);
    values.put(Phone.TYPE, Phone.TYPE_CUSTOM);
    values.put(Phone.LABEL, customLabel);
    Uri dataUri = getContentResolver().insert(Data.CONTENT_URI, values);
    
    0 讨论(0)
提交回复
热议问题