How Android replaces the call ringtone of the contact

Source: Internet
Author: User

If you know ContactID, you can get the existing ringtone like this:

Public String Getcontactrington (long contactId) {        String Rington = "";        string[] projection = {ContactsContract.Contacts.CUSTOM_RINGTONE};        Uri Contacturi = Contenturis.withappendedid (                ContactsContract.Contacts.CONTENT_URI, contactId);        cursor cursor = this.getcontentresolver (). Query (Contacturi,                projection, NULL, NULL, NULL);        if (cursor = = null) {            return rington;        }        while (Cursor.movetonext ()) {            Rington = cursor.getstring (0);            break;        }        Cursor.close ();        return Rington;    }

Use the following code to call the system interface to change the ringtone:

 private void Dopickringtone (String ringtones) {Intent Intent = new Intent (ringtonemanager.action_ringtone_picker)        ;        Intent.putextra (Ringtonemanager.extra_ringtone_show_default, true);        Intent.putextra (Ringtonemanager.extra_ringtone_type, Ringtonemanager.type_ringtone);        Intent.putextra (Ringtonemanager.extra_ringtone_show_silent, false);            try {Uri Ringtoneuri; if (ringtones! = null && ringtones.length () > 0) {ringtoneuri = Uri.parse (ri            Ngtones); } else {Ringtoneuri = Ringtonemanager. Getdefaulturi (Ringtonemanager.type_ringtone)            ;            } Intent.putextra (Ringtonemanager.extra_ringtone_existing_uri, Ringtoneuri);        Startactivityforresult (Intent, resutl_ringtone_picked);        } catch (Exception ex) {mktlog.i (TAG, "Dopickringtone:" + ex.tostring ()); }    }

Select the end of the ringtone click confirm:

  private void handleringtonepicked (Uri pickeduri) {        Updatecontactrington (mcontactid,pickeduri.tostring ());    }    public boolean Updatecontactrington (Long contactId, String Rington) {        contentvalues values = new Contentvalues (); 
   values.put (ContactsContract.Contacts.CUSTOM_RINGTONE, Rington);        Uri Contacturi = Contenturis.withappendedid (                ContactsContract.Contacts.CONTENT_URI, contactId);        This.getcontentresolver (). Update (Contacturi, values, NULL, NULL);        return true;    }


How Android replaces the call ringtone of the contact

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.