Is there a way to add a default value in a RingtonePreference, via XML? For example, here's what my preference.xml looks like.
<RingtonePreference android:key="alarm"
android:title="Alarm" android:name="Alarm"
android:summary="Select an alarm"
android:ringtoneType="alarm" android:showDefault="true" />
If possible, I'd like to set the RingtonePreference to the default ringtone, like this:
<RingtonePreference android:key="alarm"
android:title="Alarm" android:name="Alarm"
android:summary="Select an alarm"
android:ringtoneType="alarm" android:showDefault="true"
android:defaultValue="defaultRingtone" />
You can define the default in the XML. As you said, it needs a URI. Simply put the default URI for what you need. For example, for a default alarm sound you would put:
For a notification you would put:
Etc.
Figured out a work-around, in setting the default ringtone.
For the people who uses both a
RingtonePreference
andPreferenceManager.setDefaultValues()
,android:defaultValue
on aRingtonePreference
takes in a string to a ringtone's URI. By providing an empty string, you're defaulting the preference to "silence," while other strings will probably lead to no valid URI.The work-around, then, is to provide a bogus string, such as
android:defaultValue="defaultRingtone"
:When calling
PreferenceManager.setDefaultValues()
, grab the preference, and check if the bogus string is being stored: