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