141
140
Contacts.ContactMethods.PERSON_ID,
142
141
Contacts.ContactMethods.DATA,
143
142
Contacts.ContactMethods.KIND,
144
}, Contacts.ContactMethods.KIND + " IN( ?, ? )",
143
}, Contacts.ContactMethods.KIND + " IN( ?, ? )", new String[] {
146
144
"" + Contacts.KIND_EMAIL,
147
145
"" + Contacts.KIND_POSTAL,
148
146
}, Contacts.ContactMethods.ISPRIMARY + " DESC" );
197
public Long addContact( String name ) throws ContactCreationException
195
public Long addContact( String name )
199
197
ContentValues values = new ContentValues();
201
values.put( Contacts.People.NAME, name );
198
values.put( Contacts.People.NAME, name );
202
199
Uri contact_uri = _activity.getContentResolver().insert(
203
200
Contacts.People.CONTENT_URI, values );
204
201
Long id = ContentUris.parseId( contact_uri );
206
throw new ContactCreationException();
202
if( id == 0 ) id = null;
208
204
// try to add them to the "My Contacts" group
210
Contacts.People.addToMyContactsGroup(
211
_activity.getContentResolver(), id );
213
catch( IllegalStateException e ) {
214
// ignore any failure
207
Contacts.People.addToMyContactsGroup(
208
_activity.getContentResolver(), id );
210
catch( IllegalStateException e ) {
211
// ignore any failure
220
private int convertTypeToBackendType( Class< ? > cls, int type )
221
throws ContactCreationException
223
if( cls == Contacts.Phones.class )
227
case ContactData.TYPE_HOME:
228
return Contacts.Phones.TYPE_HOME;
229
case ContactData.TYPE_WORK:
230
return Contacts.Phones.TYPE_WORK;
231
case ContactData.TYPE_MOBILE:
232
return Contacts.Phones.TYPE_MOBILE;
233
case ContactData.TYPE_FAX_HOME:
234
return Contacts.Phones.TYPE_FAX_HOME;
235
case ContactData.TYPE_FAX_WORK:
236
return Contacts.Phones.TYPE_FAX_WORK;
237
case ContactData.TYPE_PAGER:
238
return Contacts.Phones.TYPE_PAGER;
241
else if( cls == Contacts.ContactMethods.class )
245
case ContactData.TYPE_HOME:
246
return Contacts.ContactMethods.TYPE_HOME;
247
case ContactData.TYPE_WORK:
248
return Contacts.ContactMethods.TYPE_WORK;
253
throw new ContactCreationException();
257
219
public void addContactPhone( Long id, String number,
258
ContactData.PreferredDetail data ) throws ContactCreationException
220
ContactData.PreferredDetail data )
260
222
Uri contact_phones_uri = Uri.withAppendedPath(
261
223
ContentUris.withAppendedId( Contacts.People.CONTENT_URI, id ),
262
224
Contacts.People.Phones.CONTENT_DIRECTORY );
264
226
ContentValues values = new ContentValues();
265
values.put( Contacts.Phones.TYPE,
266
convertTypeToBackendType( Contacts.Phones.class,
227
values.put( Contacts.Phones.TYPE, data.getType() );
268
228
values.put( Contacts.Phones.NUMBER, number );
269
229
if( data.isPreferred() )
270
230
values.put( Contacts.Phones.ISPRIMARY, 1 );
283
243
ContentValues values = new ContentValues();
284
244
values.put( Contacts.ContactMethods.KIND, Contacts.KIND_EMAIL );
285
245
values.put( Contacts.ContactMethods.DATA, email );
286
values.put( Contacts.ContactMethods.TYPE,
287
convertTypeToBackendType( Contacts.ContactMethods.class,
246
values.put( Contacts.ContactMethods.TYPE, data.getType() );
289
247
if( data.isPreferred() )
290
248
values.put( Contacts.ContactMethods.ISPRIMARY, 1 );
304
262
ContentValues values = new ContentValues();
305
263
values.put( Contacts.ContactMethods.KIND, Contacts.KIND_POSTAL );
306
264
values.put( Contacts.ContactMethods.DATA, address );
307
values.put( Contacts.ContactMethods.TYPE,
308
convertTypeToBackendType( Contacts.ContactMethods.class,
265
values.put( Contacts.ContactMethods.TYPE, data.getType() );
311
267
_activity.getContentResolver().insert( contact_contact_methods_uri,