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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:45:56+00:00 2026-06-11T16:45:56+00:00

Im developing an application which is dealing with the android contacts API. I implemented

  • 0

Im developing an application which is dealing with the android contacts API. I implemented methods to insert, update and query contacts. So far everything worked (writing and reading contacts).

At one point in my project Im experiencing a strange behaviour.

  1. I insert a contact using batch mode. I receive the URI to the RawContact. I do this in a background thread.
    ArrayList<ContentProviderOperation> ops = new  ArrayList<ContentProviderOperation>();      
                    int rawContactInsertIndex = ops.size();  
                    // create rawContact  
                    ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
                                        .withValue(RawContacts.ACCOUNT_TYPE, ConstantsContract.ACCOUNT_TYPE)
                                        .withValue(RawContacts.ACCOUNT_NAME, accountName).build());
                    ops.add(createInsertOperation().withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
                                    .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
                                    .withValue(StructuredName.DISPLAY_NAME, displayName).withValue(StructuredName.GIVEN_NAME, firstName)
                                    .withValue(StructuredName.FAMILY_NAME, lastName).build());      

        ContentProviderResult[] results = context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
if (results.length > 0) {
    result = results[0];
}
  1. Then i request and store the lookup uri
RawContacts.getContactLookupUri(this.getContentResolver(), myContantRawContactUri);
  1. I am able to query the contact using the rawContactUri directly after inserting it (in the same thread). The lookup uri returns null.
    Uri rawContactUri = appUser.getRawContactUri(ctx);
    if (rawContactUri == null) {
                return null;
            }

String lastPathSegment = rawContactUri.getLastPathSegment();
                long rawContactId = Long.decode(lastPathSegment);
                if (rawContactUri != null) {
                    contact = readContactWithID(rawContactId, ContactsContract.Data.RAW_CONTACT_ID);
  1. In a different place in the project I want to query the contact i inserted by the stored lookup uri or raw contact uri. Both return no rows from the content provider. I tried it in the main thread and in another background thread.
ctx.getContentResolver().query(ContactsContract.Data.CONTENT_URI, null,   ContactsContract.Data.RAW_CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " =   ?", new String[] { contactID + "",   ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE }, null);

My first thought was that it could be related to the context.getContentResolver(). But the android documentation states, that the ContentResolver objects scope is the application’s package, so you have on ContentResolver for the whole app. Am I right?

What am I doing wrong? Why does the same rawContactUri return the contact at one place and does not on another place? And why do I get a lookup uri from a raw contact, which is not working at all?

Update:
I analyzed the database using sqlite. When I insert the contact, the rows in raw_contacts and contacts are created. The deleted flag is set to 0, so it is not marked for deletion. If I then read the contact in another place in the application, it returns null. The database dump at this point of time does not contain the rows for the contact anymore.

Update 2:
I tested my app with the emulator in versions 2.3.3, 4.0, and 4.1. The described behavior only appears with 4.1 Jelly Bean.

  • 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-11T16:45:57+00:00Added an answer on June 11, 2026 at 4:45 pm

    Ok, i found the solution. It was actually my own fault. I added a contact before i added my custom account to the AccountManager. This obviously deleted the contact because it had the same account type set.

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

Sidebar

Related Questions

I have been developing Android application which has 3 ListView and one ContextMenu for
Am developing android application which contains floating menu effect from left to right. I
I am developing an application for ipad which is dealing with image views, bitmap
I'm developing application which needs to have functionality similer like built in Android SMS
I developing an application which works with Google API, according to my understanding. def
I am developing application which is having Gujarati font in text-view but my problem
When developing an application which mostly interacts with a database, what is a good
I`m developing an application which receives data from my GPS device like coordinates, speed
We are developing an application which is read heavy and could possibly have millions
I am developing an application which needs to connect to an embedded bluetooth device,

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.