How to check if ringtone is changed successfully to what I set?

157 Views Asked by At

That's how I change the ringtone:

RingtoneManager.setActualDefaultRingtoneUri(context, type, ringtoneUri)

How can I check if the ringtone is changed with my sound file?

 private static void setActualRingtone(@NonNull Context context, @NonNull Uri ringtoneUri, int type) {
        RingtoneManager.setActualDefaultRingtoneUri(context, type, ringtoneUri);
        if(RingtoneManager.isDefault(ringtoneUri)){
            Toast.makeText(context, "Operation successful=)", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(context, "Operation failed=)", Toast.LENGTH_SHORT).show();
        }
    }
2

There are 2 best solutions below

1
On

You can check it with the following function:

isDefault(ringtoneUri) 

For more information please refer the documentation.

0
On

I checked it like that:

 if ((RingtoneManager.getActualDefaultRingtoneUri(context, type)).equals(ringtoneUri)) {
                Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(context, context.getString(R.string.operation_failed), Toast.LENGTH_SHORT).show();
            }