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

  • Home
  • SEARCH
  • 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 9244397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:01:11+00:00 2026-06-18T09:01:11+00:00

After a lot of search I found that how we add contact programmatically in

  • 0

After a lot of search I found that how we add contact programmatically in Android. but I have a small issue in adding contact. Code which I am using:

ArrayList<ContentProviderOperation> op_list = new ArrayList<ContentProviderOperation>(); 
    op_list.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI) 
        .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, "Phone") 
        .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, "null") 
        //.withValue(RawContacts.AGGREGATION_MODE, RawContacts.AGGREGATION_MODE_DEFAULT) 
        .build()); 

 // first and last names 
      op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) 
  .withValueBackReference(Data.RAW_CONTACT_ID, 0) 
        .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE) 
        .withValue(StructuredName.GIVEN_NAME, name) 
        .withValue(StructuredName.FAMILY_NAME, name) 
        .build()); 

      op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) 
              .withValueBackReference(Data.RAW_CONTACT_ID, 0) 
              .withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
              .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, mobileNo)
              .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE )
              .build());
      op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) 
              .withValueBackReference(Data.RAW_CONTACT_ID, 0)

      .withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
      .withValue(ContactsContract.CommonDataKinds.Email.DATA, emailAddr)
      .withValue(ContactsContract.CommonDataKinds.Email.TYPE, ContactsContract.CommonDataKinds.Email.TYPE_HOME)
      .build());

 try{ 
  ContentProviderResult[] results = getContentResolver().applyBatch(ContactsContract.AUTHORITY, op_list); 
  Toast.makeText(getApplicationContext(), "Contact Added Sucessfully..", Toast.LENGTH_LONG).show();
 }catch(Exception e){ 
     Toast.makeText(getApplicationContext(), "Problem in Adding Contact ..", Toast.LENGTH_LONG).show();

  e.printStackTrace(); 
 } 

when my code is running I got following exception:

java.lang.IllegalArgumentException: Must specify both or neither of ACCOUNT_NAME and ACCOUNT_TYPE; URI: content://com.android.contacts/raw_contacts,

What I specify in this Account type and account name?

  • 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-06-18T09:01:12+00:00Added an answer on June 18, 2026 at 9:01 am

    it works for me

    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
        int rawContactInsertIndex = ops.size();
    
        Log.i("Line38", "Here");
           ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)  
                        .withValue(RawContacts.ACCOUNT_TYPE, AccountManager.KEY_ACCOUNT_TYPE)          
                        .withValue(RawContacts.ACCOUNT_NAME, AccountManager.KEY_ACCOUNT_NAME)          
                        .build());
    
        ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)      
                        .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)      
                        .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)      
                        .withValue(StructuredName.DISPLAY_NAME, "u232786seee")
                        .withValue(StructuredName.IN_VISIBLE_GROUP,true)
                        .build());
    
        ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
        .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
        .withValue(ContactsContract.Data.MIMETYPE,
                ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
        .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER,"23232343434")
        .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, "4343")
        .build());
    
        ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
        .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
        .withValue(ContactsContract.Data.MIMETYPE,
                ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
        .withValue(ContactsContract.CommonDataKinds.Email.DATA, "")
        .withValue(ContactsContract.CommonDataKinds.Email.TYPE, "")
        .build());
    
        //Log.i("Line43", Data.CONTENT_URI.toString()+" - "+rawContactInsertIndex);
    
        try {
                getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
        } catch (RemoteException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
        } catch (OperationApplicationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After a lot of search I found various solution of this question but that
I search for a lot forums but nothing found, my problem is that I
hey i made a lot of search and found some similar types of code.
After a long search around this forum, I found a lot of answers where
I have a html page that after ajax call show a lot of data
After a lot of search I am posting this Question, I have to place
I didn't know that installing ruby is such a pain After lot of trouble
After doing lot of research in Google, I found this program: #include <stdio.h> int
A lot of JavaScript libraries have user interface widgets. Usually they are created after
I found a lot of answers here to the topic, but I couldn't get

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.