|
10 | 10 | import android.provider.ContactsContract.Data;
|
11 | 11 | import android.provider.ContactsContract.RawContacts;
|
12 | 12 | import android.provider.ContactsContract.CommonDataKinds.Phone;
|
| 13 | +import android.provider.ContactsContract.CommonDataKinds.Email; |
13 | 14 | import android.provider.ContactsContract.CommonDataKinds.StructuredName;
|
14 | 15 |
|
15 | 16 | public class ContactBuilder {
|
@@ -41,15 +42,49 @@ public void assignPhoneNumber(String phoneNumber) {
|
41 | 42 | .withValue(Phone.NUMBER, phoneNumber)
|
42 | 43 | .build());
|
43 | 44 | }
|
44 |
| - |
| 45 | + |
| 46 | + public void assignEmail(String email) { |
| 47 | + ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) |
| 48 | + .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex) |
| 49 | + .withValue(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE) |
| 50 | + .withValue(Email.DATA, email) |
| 51 | + .build()); |
| 52 | + } |
| 53 | + |
45 | 54 | public void assignDisplayName(String displayName) {
|
46 | 55 | ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
|
47 | 56 | .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
|
48 | 57 | .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
|
49 | 58 | .withValue(StructuredName.DISPLAY_NAME, displayName)
|
50 | 59 | .build());
|
51 | 60 | }
|
52 |
| - |
53 |
| - //private static void assignEmail(); |
54 |
| - //private static void assignFullName(); |
| 61 | + |
| 62 | + public void assignFullName(String firstName, String lastName) { |
| 63 | + ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) |
| 64 | + .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex) |
| 65 | + .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE) |
| 66 | + .withValue(StructuredName.DISPLAY_NAME, buildFullname(firstName, lastName)) |
| 67 | + .withValue(StructuredName.GIVEN_NAME, firstName) |
| 68 | + .withValue(StructuredName.FAMILY_NAME, lastName) |
| 69 | + .build()); |
| 70 | + } |
| 71 | + |
| 72 | + public void assignFullName(String firstName, String middleName, String lastName) { |
| 73 | + ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) |
| 74 | + .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex) |
| 75 | + .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE) |
| 76 | + .withValue(StructuredName.DISPLAY_NAME, buildFullname(firstName, middleName, lastName)) |
| 77 | + .withValue(StructuredName.GIVEN_NAME, firstName) |
| 78 | + .withValue(StructuredName.MIDDLE_NAME, middleName) |
| 79 | + .withValue(StructuredName.FAMILY_NAME, lastName) |
| 80 | + .build()); |
| 81 | + } |
| 82 | + |
| 83 | + private String buildFullname(String firstName, String lastName) { |
| 84 | + return (new StringBuilder()).append(firstName).append(" ").append(lastName).toString(); |
| 85 | + } |
| 86 | + |
| 87 | + private String buildFullname(String firstName, String middleName, String lastName) { |
| 88 | + return (new StringBuilder()).append(firstName).append(" ").append(middleName).append(" ").append(lastName).toString(); |
| 89 | + } |
55 | 90 | }
|
0 commit comments