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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:17:13+00:00 2026-05-20T18:17:13+00:00

So my app is attempting to integrate a sync adapter to the android native

  • 0

So my app is attempting to integrate a sync adapter to the android native contact manager. This is all running smoothly except once a contact is synced, I am unable to update it. Details on this particular problem can be found here: Android: Content resolver query returning 0 rows when it ought not to But I can sum it up simply by just saying my content resolver query is returning 0 values because I am querying the wrong URI, I believe.

When I write the raw contact id to the phone, I do it with the following code:

public ContactSyncOperations(Context context, String username,
        String accountName, BatchOperationForSync batchOperation) {

    this(context, batchOperation);
    mBackReference = mBatchOperation.size();
    mIsNewContact = true;
    mValues.put(RawContacts.SOURCE_ID, username);
    mValues.put(RawContacts.ACCOUNT_TYPE, "com.tagapp.android");
    mValues.put(RawContacts.ACCOUNT_NAME, accountName);
    mBuilder = newInsertCpo(RawContacts.CONTENT_URI, true).withValues(mValues);
    mBatchOperation.add(mBuilder.build());
}

This constructor method is called when you are adding a new contact to the sync list:

private static void addContact(Context context, String account, Contact contact, BatchOperationForSync batchOperation) {
    ContactSyncOperations contactOp = ContactSyncOperations.createNewContact(context, contact.getUsername(), account, batchOperation);//constructor called @ this line
    contactOp.addName(contact.getFirstName(), contact.getLastName());
    contactOp.addEmail(contact.getEmail());
    contactOp.addPhone(contact.getPhoneNumber(), Phone.TYPE_MOBILE);
    contactOp.addPhone(contact.getHomePhone(), Phone.TYPE_HOME);
    contactOp.addPhone(contact.getWorkPhone(), Phone.TYPE_WORK);
    contactOp.addProfileAction(contact.getUsername());
    Log.e("Adding contact", "Via sync");
}

As you can see in the constructor, I am calling a method called newInsertCpo, which can be viewed here:

private void addInsertOp() {
    if(!mIsNewContact) {
        mValues.put(Phone.RAW_CONTACT_ID, mRawContactId);
    }
    mBuilder = newInsertCpo(addCallerIsSyncAdapterParameter(Data.CONTENT_URI), mYield);
    mBuilder.withValues(mValues);
    if(mIsNewContact) {
        mBuilder.withValueBackReference(Data.RAW_CONTACT_ID, mBackReference);
    }
    mYield = false;
    mBatchOperation.add(mBuilder.build());
}

Now that you can see the code, let me explain the problem. When I am creating and writing the raw contact id, I am doing so to RawContacts.CONTENT_URI:

mBuilder = newInsertCpo(RawContacts.CONTENT_URI, true).withValues(mValues);

However, when I query the uri, I am querying as so:

Cursor cursor = resolver.query(Data.CONTENT_URI, DataQuery.PROJECTION, DataQuery.SELECTION, new String[] {String.valueOf(rawContactId)}, null);

From Data.CONTENT_URI. I believe this is where my problem is occurring. I used the sample code from Android’s official dev site and tailored it for my own uses, but this part is pretty true to the example. Yet it is not working. My lead is what I said, I’m writing to one Uri and querying another. But I’ve attempted to change the query to RawContacts.CONTENT_URI (which caused an exception), and also changing the Uri I write to Data.CONTENT_URI, which also causes an exception. What’s even more confusing is that I get raw contact ids from Data.CONTENT_URI when I do my lookupRawContactId method:

private static long lookupRawContact(ContentResolver resolver, String username) {
    Log.e("Looking up Raw Contact", username);
    long authorId = 0;
    Cursor cursor = resolver.query(Data.CONTENT_URI, UserIdQuery.PROJECTION, UserIdQuery.SELECTION, new String[] {username}, null);

    try {
        if(cursor != null && cursor.moveToFirst()) {
            authorId = cursor.getLong(UserIdQuery.COLUMN_ID);
        }
    } finally {
        if(cursor != null) {
            cursor.close();
        }
    }
    return authorId;
}

So yea, if I get a cursor returning rawcontactId, why would I get 0 values querying that same Uri with that same rawcontactId i was returned? It doesn’t make any sense! Does anyone have any insight? Thanks all.

  • 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-20T18:17:14+00:00Added an answer on May 20, 2026 at 6:17 pm

    The lookupRawContactId method should look like this instead:

    private static long lookupRawContact(ContentResolver resolver, String username) {
        Log.e("Looking up Raw Contact", username);
        long authorId = 0;
        Cursor cursor = resolver.query(RawContacts.CONTENT_URI, UserIdQuery.PROJECTION, UserIdQuery.SELECTION, new String[] {username}, null);
    
        try {
            if(cursor != null && cursor.moveToFirst()) {
                authorId = cursor.getLong(UserIdQuery.COLUMN_ID);
            }
        } finally {
            if(cursor != null) {
                cursor.close();
            }
        }
        return authorId;
    }
    

    Notice the query is searching RawContacts.CONTENT_URI instead.

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

Sidebar

Related Questions

Im attempting to style this plugin into my rails 3.2 app and having some
I am attempting to develop an Android app that allows a user to write
I am attempting to write an Android app which will allow me to read
I'm creating my first android app (or attempting to anyway) and i have a
I'm attempting to integrate the Flurry SDK into my iOS app for the first
I have an app that I'm attempting to integrate hibernate search into. I'm using
I'm OK with the java for this beginning app I'm attempting. But the XML
I'm attempting to create an Android app which graphs simple mathematical functions that the
I'm attempting to write an app that involves connecting two android devices via bluetooth.
I'm attempting to run an Android app, that makes use of Google's map API,

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.