Here is my code snippet to play ringtone notification:
Uri u = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(MainActivity.this, u);
r.play();
This seems to work fine on most devices. However, on some devices such as Samsung S8 and Samsung S9, it does not work. Logcat shows:
I/Ringtone: Internal uri : content://settings/system/notification_sound
D/RingtoneManager: getActualDefaultRingtoneUri type :2
W/MediaPlayer: Couldn't open content://0@settings/system/notification_sound_cache:
java.io.FileNotFoundException: open failed: ENOENT (No such file or directory)
Note that the same code works fine on Samsung S7.
Wondering if anyone has any insight.