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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:05:37+00:00 2026-05-26T06:05:37+00:00

I’m trying to add a contact in android from my application. For that I

  • 0

I’m trying to add a contact in android from my application. For that I get all the data and pass it via intent.

And, What I’m trying to do is when inserting, it opens the Add Contact screen, so the user may edit it, so I’m trying using the ACTION_EDIT.

public void addNewContactToDevice() 
    {   
        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
        int rawContactInsertIndex = ops.size();
        ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
            .withValue(RawContacts.ACCOUNT_TYPE, null)
            .withValue(RawContacts.ACCOUNT_NAME, null)
            .build());
        ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
            .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
            .withValue(StructuredName.GIVEN_NAME, person.getName())
            .withValue(StructuredName.FAMILY_NAME, person.getLastName())
            .build());  
        ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
            .withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
            .withValue(Phone.NUMBER, person.getPhone())
            .withValue(Phone.TYPE, Phone.TYPE_MOBILE)                
            .build());

        try 
        {
            ((Panel)activity).getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
            Cursor contactsCursor = activity.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
                    new String[] {ContactsContract.Contacts.LOOKUP_KEY, ContactsContract.CommonDataKinds.Phone.RAW_CONTACT_ID}, 
                    ContactsContract.CommonDataKinds.Phone.NUMBER + " = ?" , 
                    new String[] { PhoneNumberUtils.formatNumber(individualSelected.getPhone()) }, null);

            contactsCursor.moveToFirst();

            String androidContactId = contactsCursor.getString(contactsCursor.getColumnIndex(LOOKUP_KEY));

            Intent intent = new Intent(Intent.ACTION_EDIT);
            intent.setData(Uri.parse(ContactsContract.Contacts.CONTENT_LOOKUP_URI + "/" + androidContactId));
            ((Panel)activity).startActivityForResult(intent, 2);
        } 
        catch (RemoteException e) 
        {
            e.printStackTrace();
        } 
        catch (OperationApplicationException e) 
        {
            e.printStackTrace();
        }   

    }

But the problem is that, passing ACTION_EDIT returns a NumberFormatException for the LOOKUP_KEY (that is something like this 0r17-3E483A46442C32324838). When it tries to open the Add Contact screen, it cant parse the LOOKUP_KEY.

What am I supposed to do?

Thanks.


UPDATE: here is the logcat

10-18 08:54:59.003: ERROR/AndroidRuntime(7527): Caused by: java.lang.NumberFormatException: 0r17-3E483A46442C32324838
10-18 08:54:59.003: ERROR/AndroidRuntime(7527):     at java.lang.Long.parse(Long.java:364)
10-18 08:54:59.003: ERROR/AndroidRuntime(7527):     at java.lang.Long.parseLong(Long.java:354)
10-18 08:54:59.003: ERROR/AndroidRuntime(7527):     at java.lang.Long.parseLong(Long.java:320)
10-18 08:54:59.003: ERROR/AndroidRuntime(7527):     at android.content.ContentUris.parseId(ContentUris.java:41)
10-18 08:54:59.003: ERROR/AndroidRuntime(7527):     at com.android.contacts.ui.EditContactActivity$QueryEntitiesTask.doInBackground(EditContactActivity.java:497)
10-18 08:54:59.003: ERROR/AndroidRuntime(7527):     at com.android.contacts.ui.EditContactActivity$QueryEntitiesTask.doInBackground(EditContactActivity.java:471)
10-18 08:54:59.003: ERROR/AndroidRuntime(7527):     at com.android.contacts.util.WeakAsyncTask.doInBackground(WeakAsyncTask.java:45)
10-18 08:54:59.003: ERROR/AndroidRuntime(7527):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
10-18 08:54:59.003: ERROR/AndroidRuntime(7527):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
  • 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-26T06:05:38+00:00Added an answer on May 26, 2026 at 6:05 am

    I found a solution for this, instead of passing this to the setData method:

    intent.setData(Uri.parse(ContactsContract.Contacts.CONTENT_LOOKUP_URI + "/" + androidContactId));
    

    I should be passing this:

    Uri lookupUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookup_key);
    Uri res = ContactsContract.Contacts.lookupContact(activity.getContentResolver(), lookupUri);
    

    and in the setData() method, I pass the variable res, that is a URI type.


    This question helped me a lot!

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

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.