Y. Leonce Eyog
Y. Leonce Eyog

Reputation: 903

Android - Check the phone number type

I'd like to update the contacts in my phone according to a certain logic. When I write them back to the database, I have to determine the type under which it is stored using the for example for mobile contact.

ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE

// Number mobile       
builder = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI);
builder.withSelection(ContactsContract.Data.CONTACT_ID + "=?" + " AND " + ContactsContract.Data.MIMETYPE + "=?"+ " AND " + ContactsContract.CommonDataKinds.Organization.TYPE + "=?", new String[]{String.valueOf(id), ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE, String.valueOf(ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE)});
builder.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, number);
ops.add(builder.build());

I want to put in a switch case to be able to check for the appropriate type from either: TYPE_WORK TYPE_HOME TYPE_COMPANY_MAIN TYPE_ASSISTANT TYPE_ISDN

but I'm a little clueless on what key to use. Can anyone help?

Upvotes: 0

Views: 213

Answers (1)

Mohammed Ali
Mohammed Ali

Reputation: 2926

Use int type:

int number_type; // the type of phone no. to update
switch(number_type)
{
 case ContactsContract.CommonDataKinds.Phone.TYPE_WORK:
    // your code for update..
  break;
 case ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE:
    // and so on....
  break;
}

Upvotes: 1

Related Questions