I have developed an Android application for changing ringtones. It works quite well, but one thing bothers me.
When I set a ringtone as a notification tone, it plays when I receive an SMS message. However, if I have chosen a custom SMS tone earlier (ie. anything else than "Default ringtone" which is active by default) in the SMS settings, the new notification tone will not play when I receive an SMS.
This might lead to a situation in which someone installs the ringtone app from the Android market, sets the notification tone and gets disappointed because the chosen notification will not play when (s)he receives an SMS. The solution is quite easy (SMS -> Settings -> Select ringtone -> Default ringtone), but it's truly a nuisance if (s)he doesn't know this.
This is what I use to set the notification tone:
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
values.put(MediaStore.Audio.Media.IS_ALARM, true);
.....
RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_NOTIFICATION, persistentUri);
You can't do this unless you do it as root.
The ringtone used by the stock MMS/SMS application is stored in its own shared_preferences. As every shared_preference is only accessable by its owner (this is enforced by android, unless you are root) it's simply not possible.
You can look it up yourself if you have a rooted phone (or just use an emulator) and look at /data/data/com.android.mms/shared_prefs/com.android.mms_preferences.xml
on the device via adb shell
.
It contains the shared_preferences used by the app and also contains a key pref_key_ringtone
which contains a content URI.
Edit:
I have not confirmed this, but I think the default value of the pref_key_ringtone
will be set to Settings.System.DEFAULT_NOTIFICATION_URI. This will route to the system default notification sound when played. When the user has not changed this, your solution will work.