Search code examples
androidringtone

How to reset ringtone back in android programmatically


I've used the following code to set the ringtone in my app which is working fine. Now i would like to provide the option to remove the ringtone and reset the ringtone back. Please help me on this. Thanks in advance.

            Uri path = Uri.parse("android.resource://"
                                + getPackageName() + "/raw/ringtone");
            RingtoneManager.setActualDefaultRingtoneUri(
                                getApplicationContext(),
                                RingtoneManager.TYPE_RINGTONE, path);

Solution

  • After taking existingRingtonepath, you can set your custom ringtone path.

    Uri existingRingtonePath = getDefaultUri(RingtoneManager.TYPE_RINGTONE);
    

    After that you can use it to revert back.

    RingtoneManager.setActualDefaultRingtoneUri(
                                    getApplicationContext(),
                                    RingtoneManager.TYPE_RINGTONE, existingRinftonePath);
    

    If you want to revert to default then,

    RingtoneManager.setActualDefaultRingtoneUri(
                                    getApplicationContext(),
                                    RingtoneManager.TYPE_RINGTONE, RingtoneManager.DEFAULT_RINGTONE_URI);