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 7827175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:44:52+00:00 2026-06-02T09:44:52+00:00

Possible Duplicate: How can I programmatically add a contact? With the help of a

  • 0

Possible Duplicate:
How can I programmatically add a contact?

With the help of a Google search I was able to add a Contact in my Android Application. While this works, I am not able to see that added Contact in the phone Contact List (Phonebook).

Could you help me fix this? I don’t know where to look, is it perhaps a versioning problem? I would be grateful if anyone who has encountered this problem would care to help me out.

I have followed this example in setting up my code.

  • 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-02T09:44:53+00:00Added an answer on June 2, 2026 at 9:44 am

    Insert a new contact into your phone book with the following method:

    public void insert(String lastName, String firstName, String phoneNumber, String photo_uri)
    {
        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
    
        Builder builder = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
        builder.withValue(RawContacts.ACCOUNT_TYPE, null);
        builder.withValue(RawContacts.ACCOUNT_NAME, null);
        ops.add(builder.build());
    
        // Name
        builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
        builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0);
        builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
        builder.withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, lastName);
        builder.withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, firstName);
        ops.add(builder.build());
    
        // Number
        builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
        builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0);
        builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
        builder.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phoneNumber);
        builder.withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_HOME);
        ops.add(builder.build());
    
        // Picture
        try
        {
            Bitmap mBitmap = Media.getBitmap(context.getContentResolver(), Uri.parse(photo_uri));
    
            ByteArrayOutputStream image = new ByteArrayOutputStream();
            mBitmap.compress(Bitmap.CompressFormat.JPEG , 100, image);
    
            builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
            builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0);
            builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
            builder.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, image.toByteArray());
            ops.add(builder.build());
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    
        // Add the new contact
        ContentProviderResult[] res;
        try
        {
            res = KramerApplication.getInstance().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
            if (res != null && res[0] != null)
            {
                String uri = res[0].uri.getPath().substring(14);
                return new Integer(uri).intValue(); // Book ID
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
    

    Usage:

    int book_id = insert("Doe", "John", "111-222-333", "content://com.my.package/drawable/photo");

    book_id is the row id of your entry.

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

Sidebar

Related Questions

Possible Duplicate: How can I enable or disable the GPS programmatically on Android? I
Possible Duplicate: Can you animate a height change on a UITableViewCell when selected? This
Possible Duplicate: How can I pre-set arguments in JavaScript function call? (Partial Function Application)
Possible Duplicate: Change Backlight Brightness on iPhone Programmatically How can i adjust brightness in
Possible Duplicate: How Turn on only Camera flash light programmatically in android? I am
Possible Duplicate: In JavaScript can I make a “click” event fire programmatically for a
Possible Duplicate: Programmatically find device support GPS or not? How can I check, is
Possible Duplicate: How to set android lock screen image I was able to set
Possible Duplicate: Can Google Maps/Places 'autocomplete' API be used via AJAX? There seems to
Possible Duplicate: Can I embed a custom font in an iPhone application? Hi I

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.