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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:32:13+00:00 2026-05-27T16:32:13+00:00

So I am doing Account Sync, and included in that process is a step

  • 0

So I am doing Account Sync, and included in that process is a step where a custom ringtone is added. Here is my method for adding a ringtone:

private static void ringtoneSync(ContentResolver resolver, String username, Context context) {
    ContentValues values = new ContentValues();
    Log.e("SYNC", "setting ringtone for " + username);

    long rawContactId = lookupRawContact(resolver, username);
    long contactId = getContactId(resolver, rawContactId);

    File root = Environment.getExternalStorageDirectory();
    TagDBAdapter adapter = new TagDBAdapter(context);
    adapter.open();
    String ringtone = adapter.getContactRingtonePath(username);
    adapter.close();

    Log.e("test", "ringtone checkpoint name here: " + ringtone);

    File file = new File(root, "tag/ringtones/"+ ringtone + ".mp3");
    if(file.exists()) {

        Log.e("test", "ringtone checkpoint if file exists");

        Uri oldUri = MediaStore.Audio.Media.getContentUriForPath(file.getAbsolutePath());
        resolver.delete(oldUri, MediaStore.MediaColumns.DATA + "=\"" + file.getAbsolutePath() + "\"", null);

        values.put(MediaStore.MediaColumns.DATA, file.getAbsolutePath());
        values.put(MediaStore.MediaColumns.TITLE, ringtone);
        values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
        values.put(MediaStore.Audio.Media.IS_RINGTONE, true);

        Uri uri = MediaStore.Audio.Media.getContentUriForPath(file.getAbsolutePath());
        Uri newUri = resolver.insert(uri, values);
        String uriString = newUri.toString();
        values.put(ContactsContract.Contacts.CUSTOM_RINGTONE, uriString);
        Log.e("Uri String for " + username, uriString);
        resolver.update(ContactsContract.Contacts.CONTENT_URI, values, Contacts._ID + "=" + contactId, null);
    }
}

This method works great, except when I am adding a contact to the account for the first time beforehand. My call to adding contacts is structured like this:

    for(Contact contact : friends) {
        Log.e("SYNCING CONTACTS", "Start for loop");
        username = contact.getUsername();
        rawContactId = lookupRawContact(resolver, username);
        if(rawContactId != 0) {
            if(!contact.isDeleted()) {
                Log.e("SYNCING CONTACTS", "Updating " + username);
                updateContact(context, resolver, account, contact, rawContactId, batchOperation);
                ringtoneSync(resolver, username, context);

            }
            else {
                Log.e("SYNCING CONTACTS", "Deleting " + username);
                deleteContact(context, rawContactId, batchOperation);
            }
        }
        else {
            if(!contact.isDeleted()) {
                Log.e("SYNCING CONTACTS", "Adding " + username);
                addContact(context, account, contact, batchOperation);
                ringtoneSync(resolver, username, context);
            }
        }

So as you can see it is called very similarly regardless if it is a new or existing contact, but it only actually works for an existing contact. What’s more, all those log lines I entered in as checkpoints are displayed accurately in logcat even when the ringtone is not successfully added.

I can’t figure out for the life of me what is going on here, any thoughts?

  • 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-27T16:32:14+00:00Added an answer on May 27, 2026 at 4:32 pm

    Found an answer to my question. I should ask SO questions sooner, it seems as soon as I ask it the answer comes to me, even if I was working on the issue for days.

    Anyways, here is what is going on: the ringtoneSync method is looking for a rawContactId, which is created when you do the addContact() method. Problem is, the rawContactId is not committed until you call batchOperation.execute().

    So by changing my contact adding loop from this:

            if(rawContactId != 0) {
                if(!contact.isDeleted()) {
                    Log.e("SYNCING CONTACTS", "Updating " + username);
                    updateContact(context, resolver, account, contact, rawContactId, batchOperation);
                    ringtoneSync(resolver, username, context);
    
                }
                else {
                    Log.e("SYNCING CONTACTS", "Deleting " + username);
                    deleteContact(context, rawContactId, batchOperation);
                }
            }
            else {
                if(!contact.isDeleted()) {
                    Log.e("SYNCING CONTACTS", "Adding " + username);
                    addContact(context, account, contact, batchOperation);
                    ringtoneSync(resolver, username, context);
                }
            }
    

    To this:

            if(rawContactId != 0) {
                if(!contact.isDeleted()) {
                    Log.e("SYNCING CONTACTS", "Updating " + username);
                    updateContact(context, resolver, account, contact, rawContactId, batchOperation);
                    ringtoneSync(resolver, username, context);
    
                }
                else {
                    Log.e("SYNCING CONTACTS", "Deleting " + username);
                    deleteContact(context, rawContactId, batchOperation);
                }
            }
            else {
                if(!contact.isDeleted()) {
                    Log.e("SYNCING CONTACTS", "Adding " + username);
                    addContact(context, account, contact, batchOperation);
    /* -------> */  batchOperation.execute(); //EXECUTE BATCH OPERATION BEFORE SYNCING RINGTONE
                    ringtoneSync(resolver, username, context);
                }
            }
    

    The process works fine.

    Hope this can help someone else out in the future.

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

Sidebar

Related Questions

I've been doing some logging of object creation times in our open account process
I am not sure am I doing these correct. I have 3 models, Account,
I'm doing a Java task that is like a simple bank system with Customer
I have a database in which there is a parent Account row that then
You know those websites that let you type in your checking account number and
We currently have a website that has user account functionality, but we are looking
I am doing an Ajax call from site.com/users/{username} i wanna access the url site.com/account/deleteComment
I am doing functional tests and just discovered assert_difference, as in: assert_difference('Account.count') do post
We implemented Android's Account Manager and Sync Manager api to create contact sync. But
When i login in to my mysql account i doing something like this: mysql>TRUNCATE

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.