Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6081941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:13:59+00:00 2026-05-23T11:13:59+00:00

Im using the new’ish API to insert/update contacts on my phone and I’m using

  • 0

Im using the new’ish API to insert/update contacts on my phone and I’m using this method to updates them..

String selectArgs1 = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='"  + Note.CONTENT_ITEM_TYPE + "'" + " AND " + Email.TYPE + "=?";
    String[] selectArgs2 = new String[]{contactId, String.valueOf(Email.TYPE_OTHER)}; 
    operationList.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
            .withSelection(selectArgs1, selectArgs2)
            .withValue(Note.Note, "hello@hi.com")
            .build());

This is all working fine, except for when i get to updating a Note. There isn’t a Note.Type_1 or anything like that, so i don’t know what to put in the selectArgs1 and selectArgs2 in replace of Email.TYPE and String.valueOf(Email.TYPE_OTHER)

Any help would be much apreciated. Thanks! 🙂

[Edit]

public static void updateContact(Context c, int recordId, String key, String value) {
    context = c;
    if (database == null) database = new SavedContactsDatabase(context);
    ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
    ContentProviderOperation.Builder builder = ContentProviderOperation.newUpdate(Data.CONTENT_URI);
    String contactId = String.valueOf(recordId);
    String selectArgs1 = "";
    String[] selectArgs2 = null;

    String type = "";
    String subkey = "";
    if (key.contains(":")) {
        String[] split = key.split(":");
        key = split[0];
        type = split[1];
        if (split.length == 3) subkey = split[2];
    }

    if (key.equals("Email")) {
        if (type.equals("Home")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Email.TYPE_HOME)};
        } else if (type.equals("Work")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Email.TYPE_WORK)};
        } else if (type.equals("Mobile")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Email.TYPE_MOBILE)};
        }
        selectArgs1 = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='"  + Email.CONTENT_ITEM_TYPE + "'" + " AND " + Email.TYPE + "=?";
        builder.withSelection(selectArgs1, selectArgs2);
        builder.withValue(Email.DATA1, value);
    }

    if (key.equals("Nickname")) {
        if (type.equals("Default")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Nickname.TYPE_DEFAULT)};
        } else if (type.equals("Other Names")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Nickname.TYPE_OTHER_NAME)};
        } else if (type.equals("Maiden Name")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Nickname.TYPE_MAINDEN_NAME)};
        } else if (type.equals("Short Name")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Nickname.TYPE_SHORT_NAME)};
        } else if (type.equals("Initials")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Nickname.TYPE_INITIALS)};
        }
        selectArgs1 = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='"  + Nickname.CONTENT_ITEM_TYPE + "'" + " AND " + Nickname.TYPE + "=?";
        builder.withSelection(selectArgs1, selectArgs2);
        builder.withValue(Nickname.NAME, value);
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////
    if (key.equals("Note")) {
        selectArgs1 = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='"  + Note.CONTENT_ITEM_TYPE + "'";
        selectArgs2 = new String[]{contactId, "vnd.android.cursor.item/note"}; 
        builder.withSelection(selectArgs1, selectArgs2);
        builder.withValue(Note.NOTE, "hello@hi.com");

    }
    /////////////////////////////////////////////////////////////////////////////////////////////////////

    if (key.equals("Organization")) {
        String data = "";
        if (type.equals("Company")) {
            data = Organization.COMPANY;
        } else if (type.equals("Title")) {
            data = Organization.TITLE;
        } else if (type.equals("Department")) {
            data = Organization.DEPARTMENT;
        } else if (type.equals("Job Descripiton")) {
            data = Organization.JOB_DESCRIPTION;
        } else if (type.equals("Symbol")) {
            data = Organization.SYMBOL;
        } else if (type.equals("Phonetic Name")) {
            data = Organization.PHONETIC_NAME;
        } else if (type.equals("Office Location")) {
            data = Organization.OFFICE_LOCATION;
        }
        selectArgs1 = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='"  + Organization.CONTENT_ITEM_TYPE + "'" + " AND " + Organization.TYPE + "=?";
        selectArgs2 = new String[]{contactId, String.valueOf(Organization.TYPE_WORK)};
        builder.withSelection(selectArgs1, selectArgs2);
        builder.withValue(data, value);
    }

    if (key.equals("Phone")) {
        if (type.equals("Home")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_HOME)};
        } else if (type.equals("Mobile")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_MOBILE)};
        } else if (type.equals("Work")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_WORK)};
        } else if (type.equals("Fax Work")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_FAX_WORK)};
        } else if (type.equals("Fax Home")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_FAX_HOME)};
        } else if (type.equals("Pager")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_PAGER)};
        } else if (type.equals("Other")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_OTHER)};
        } else if (type.equals("Callback")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_CALLBACK)};
        } else if (type.equals("Car")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_CAR)};
        } else if (type.equals("Company Main")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_COMPANY_MAIN)};
        } else if (type.equals("ISDN")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_ISDN)};
        } else if (type.equals("Main")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_MAIN)};
        } else if (type.equals("Other Fax")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_OTHER_FAX)};
        } else if (type.equals("Radio")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_RADIO)};
        } else if (type.equals("Telex")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_TELEX)};
        } else if (type.equals("TTY TDD")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_TTY_TDD)};
        } else if (type.equals("Work Mobile")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_WORK_MOBILE)};
        } else if (type.equals("Work Pager")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_WORK_PAGER)};
        } else if (type.equals("Assistant")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_ASSISTANT)};
        } else if (type.equals("MMS")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Phone.TYPE_MMS)};
        }
        selectArgs1 = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='"  + Phone.CONTENT_ITEM_TYPE + "'" + " AND " + Phone.TYPE + "=?";
        builder.withSelection(selectArgs1, selectArgs2);
        builder.withValue(Phone.NUMBER, value);
    }

    //TODO Relation?

    //////////////////////////////////////////////////////////////////////////////////////
    if (key.equals("Name")) {
        String data = "";
        if (type.equals("Display Name")) {
            data = StructuredName.DISPLAY_NAME;
        } else if (type.equals("Given Name")) {
            data = StructuredName.GIVEN_NAME;
        } else if (type.equals("Family Name")) {
            data = StructuredName.FAMILY_NAME;
        } else if (type.equals("Prefix")) {
            data = StructuredName.PREFIX;
        } else if (type.equals("Middle Name")) {
            data = StructuredName.MIDDLE_NAME;
        } else if (type.equals("Suffix")) {
            data = StructuredName.SUFFIX;
        } else if (type.equals("Phonetic Given Name")) {
            data = StructuredName.PHONETIC_GIVEN_NAME;
        } else if (type.equals("Phonetic Middle Name")) {
            data = StructuredName.PHONETIC_MIDDLE_NAME;
        } else if (type.equals("Phonetic Family Name")) {
            data = StructuredName.PHONETIC_FAMILY_NAME;
        }
        selectArgs1 = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='"  + StructuredName.CONTENT_ITEM_TYPE + "'" + " AND " + StructuredName.MIMETYPE + "=?";
        selectArgs2 = new String[]{contactId, String.valueOf(StructuredName.MIMETYPE)};
        builder.withSelection(selectArgs1, selectArgs2);
        builder.withValue(data, value);
    }
    ////////////////////////////////////////////////////////////////////////////////////////

    if (key.equals("Address")) {
        String data = "";
        if (type.equals("Home")) {
            selectArgs2 = new String[]{contactId, String.valueOf(CommonDataKinds.StructuredPostal.TYPE_HOME)};
        } else if (type.equals("Work")) {
            selectArgs2 = new String[]{contactId, String.valueOf(CommonDataKinds.StructuredPostal.TYPE_WORK)};
        } else if (type.equals("Other")) {
            selectArgs2 = new String[]{contactId, String.valueOf(CommonDataKinds.StructuredPostal.TYPE_OTHER)};
        }
        if (subkey.equals("Street")) {
            data = CommonDataKinds.StructuredPostal.STREET;
        } else if (subkey.equals("PO Box")) {
            data = CommonDataKinds.StructuredPostal.POBOX;
        } else if (subkey.equals("Neighbourhood")) {
            data = CommonDataKinds.StructuredPostal.NEIGHBORHOOD;
        } else if (subkey.equals("City")) {
            data = CommonDataKinds.StructuredPostal.CITY;
        } else if (subkey.equals("Region")) {
            data = CommonDataKinds.StructuredPostal.REGION;
        } else if (subkey.equals("Postcode")) {
            data = CommonDataKinds.StructuredPostal.POSTCODE;
        } else if (subkey.equals("Country")) {
            data = CommonDataKinds.StructuredPostal.COUNTRY;
        }
        selectArgs1 = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='"  + CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE + "'" + " AND " + CommonDataKinds.StructuredPostal.TYPE + "=?";
        builder.withSelection(selectArgs1, selectArgs2);
        builder.withValue(data, value);
    }

    if (key.equals("Website")) {
        if (type.equals("Homepage")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Website.TYPE_HOMEPAGE)};
        } else if (type.equals("Blog")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Website.TYPE_BLOG)};
        } else if (type.equals("Profile")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Website.TYPE_PROFILE)};
        } else if (type.equals("Home")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Website.TYPE_HOME)};
        } else if (type.equals("Work")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Website.TYPE_WORK)};
        } else if (type.equals("FTP")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Website.TYPE_FTP)};
        }
        selectArgs1 = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='"  + Website.CONTENT_ITEM_TYPE + "'" + " AND " + Website.TYPE + "=?";
        builder.withSelection(selectArgs1, selectArgs2);
        builder.withValue(Website.URL, value);
    }

    if (key.equals("Event")) {
        if (type.equals("Anniversary")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Event.TYPE_ANNIVERSARY)};
        } else if (type.equals("Birthday")) {
            selectArgs2 = new String[]{contactId, String.valueOf(Event.TYPE_BIRTHDAY)};
        }
        selectArgs1 = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='"  + Event.CONTENT_ITEM_TYPE + "'" + " AND " + Event.TYPE + "=?";
        builder.withSelection(selectArgs1, selectArgs2);
        builder.withValue(Event.START_DATE, value);
    }





    /*
    operationList.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
            .withSelection(Data.RAW_CONTACT_ID + "=?", new String[] {sdf})
            .withValue(Email.DATA1, "work.hi.com")
            .withValue(Email.TYPE, Email.TYPE_WORK)
            .build());  
    */
    /*
    String selectPhone = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='"  + 
    Email.CONTENT_ITEM_TYPE + "'" + " AND " + Email.TYPE + "=?";
    String[] phoneArgs = new String[]{contactId, String.valueOf(Email.TYPE_OTHER)}; 
    operationList.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
            .withSelection(selectPhone, phoneArgs)
            .withValue(Email.DATA1, "hello@hi.comm")
            .build()); 
    */

    try {
        operationList.add(builder.build());
        ContentProviderResult[] res = context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, operationList);
        if (res[0].count == 0) {
            //TODO Then Use the Insert Command Instead!
        }
    } catch (Exception e) { Log.d("fhksdsdj", e.toString()); }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:13:59+00:00Added an answer on May 23, 2026 at 11:13 am
    String selectArgs1 = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "= ? ";
        String[] selectArgs2 = new String[]{contactId, "vnd.android.cursor.item/note"}; 
        operationList.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
                .withSelection(selectArgs1, selectArgs2)
                .withValue(ContactsContract.CommonDataKinds.Note.NOTE, "hello@hi.com")
                .build());
    

    try this code…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about using new[] . Imagine this: Object.SomeProperty = new[] {string1,
ADO.NET has the notorious DataRow class which you cannot instantiate using new. This is
Considering the code below: How is the str1 object created without using new String()
In java String can be created by using new operator or by using +
I have this test in my test base: public void WorksWithAreaUsers() { using (new
Possible Duplicate: What is difference between instantiating an object using new vs. without This
I am unable to update the record in SharePoint 2010 using new linq feature.
I have this code: FileDownloadHandler handler = new FileDownloadHandler(fileName); Browser.AddDialogHandler(handler); //using (new UseDialogOnce(Browser.DialogWatcher, handler))
I create a map using new MapMaker().softValues().maximumSize(cacheSize).makeMap(); This seemed to work fine, however, I
I create a java.util.concurrent.locks.ReentrantReadWriteLock using new java.util.concurrent.locks.ReentrantReadWriteLock().readLock() and then I pass to a method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.