public class

RingtonePreference

extends Preference
implements PreferenceManager.OnActivityResultListener
java.lang.Object
   ↳ android.preference.Preference
     ↳ android.preference.RingtonePreference

Class Overview

A Preference that allows the user to choose a ringtone from those on the device. The chosen ringtone's URI will be persisted as a string.

If the user chooses the "Default" item, the saved string will be one of DEFAULT_RINGTONE_URI, DEFAULT_NOTIFICATION_URI, or DEFAULT_ALARM_ALERT_URI. If the user chooses the "Silent" item, the saved string will be an empty string.

Summary

XML Attributes
Attribute Name Related Method Description
android:ringtoneType Which ringtone type(s) to show in the picker. 
android:showDefault Whether to show an item for a default sound. 
android:showSilent Whether to show an item for 'Silent'. 
[Expand]
Inherited XML Attributes
From class android.preference.Preference
[Expand]
Inherited Constants
From class android.preference.Preference
Public Constructors
RingtonePreference(Context context, AttributeSet attrs, int defStyle)
RingtonePreference(Context context, AttributeSet attrs)
RingtonePreference(Context context)
Public Methods
int getRingtoneType()
Returns the sound type(s) that are shown in the picker.
boolean getShowDefault()
Returns whether to a show an item for the default sound/ringtone.
boolean getShowSilent()
Returns whether to a show an item for 'Silent'.
boolean onActivityResult(int requestCode, int resultCode, Intent data)
See Activity's onActivityResult.
void setRingtoneType(int type)
Sets the sound type(s) that are shown in the picker.
void setShowDefault(boolean showDefault)
Sets whether to show an item for the default sound/ringtone.
void setShowSilent(boolean showSilent)
Sets whether to show an item for 'Silent'.
Protected Methods
void onAttachedToHierarchy(PreferenceManager preferenceManager)
Called when this Preference has been attached to a Preference hierarchy.
void onClick()
Processes a click on the preference.
Object onGetDefaultValue(TypedArray a, int index)
Called when a Preference is being inflated and the default value attribute needs to be read.
void onPrepareRingtonePickerIntent(Intent ringtonePickerIntent)
Prepares the intent to launch the ringtone picker.
Uri onRestoreRingtone()
Called when the chooser is about to be shown and the current ringtone should be marked.
void onSaveRingtone(Uri ringtoneUri)
Called when a ringtone is chosen.
void onSetInitialValue(boolean restorePersistedValue, Object defaultValueObj)
Implement this to set the initial value of the Preference.
[Expand]
Inherited Methods
From class android.preference.Preference
From class java.lang.Object
From interface android.preference.PreferenceManager.OnActivityResultListener
From interface java.lang.Comparable

XML Attributes

android:ringtoneType

Since: API Level

Which ringtone type(s) to show in the picker.

Must be one or more (separated by '|') of the following constant values.

ConstantValueDescription
ringtone1 Ringtones.
notification2 Notification sounds.
alarm4 Alarm sounds.
all7 All available ringtone sounds.

This corresponds to the global attribute resource symbol ringtoneType.

Related Methods

android:showDefault

Since: API Level

Whether to show an item for a default sound.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol showDefault.

Related Methods

android:showSilent

Since: API Level

Whether to show an item for 'Silent'.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol showSilent.

Related Methods

Public Constructors

public RingtonePreference (Context context, AttributeSet attrs, int defStyle)

Since: API Level 1

public RingtonePreference (Context context, AttributeSet attrs)

Since: API Level 1

public RingtonePreference (Context context)

Since: API Level 1

Public Methods

public int getRingtoneType ()

Since: API Level 1

Returns the sound type(s) that are shown in the picker.

Returns
  • The sound type(s) that are shown in the picker.

public boolean getShowDefault ()

Since: API Level 1

Returns whether to a show an item for the default sound/ringtone.

Returns
  • Whether to show an item for the default sound/ringtone.

public boolean getShowSilent ()

Since: API Level 1

Returns whether to a show an item for 'Silent'.

Returns
  • Whether to show an item for 'Silent'.

public boolean onActivityResult (int requestCode, int resultCode, Intent data)

Since: API Level 1

See Activity's onActivityResult.

Returns
  • Whether the request code was handled (in which case subsequent listeners will not be called.

public void setRingtoneType (int type)

Since: API Level 1

Sets the sound type(s) that are shown in the picker.

Parameters
type The sound type(s) that are shown in the picker.

public void setShowDefault (boolean showDefault)

Since: API Level 1

Sets whether to show an item for the default sound/ringtone. The default to use will be deduced from the sound type(s) being shown.

Parameters
showDefault Whether to show the default or not.

public void setShowSilent (boolean showSilent)

Since: API Level 1

Sets whether to show an item for 'Silent'.

Parameters
showSilent Whether to show 'Silent'.

Protected Methods

protected void onAttachedToHierarchy (PreferenceManager preferenceManager)

Since: API Level 1

Called when this Preference has been attached to a Preference hierarchy. Make sure to call the super implementation.

Parameters
preferenceManager The PreferenceManager of the hierarchy.

protected void onClick ()

Since: API Level 1

Processes a click on the preference. This includes saving the value to the SharedPreferences. However, the overridden method should call callChangeListener(Object) to make sure the client wants to update the preference's state with the new value.

protected Object onGetDefaultValue (TypedArray a, int index)

Since: API Level 1

Called when a Preference is being inflated and the default value attribute needs to be read. Since different Preference types have different value types, the subclass should get and return the default value which will be its value type.

For example, if the value type is String, the body of the method would proxy to getString(int).

Parameters
a The set of attributes.
index The index of the default value attribute.
Returns
  • The default value of this preference type.

protected void onPrepareRingtonePickerIntent (Intent ringtonePickerIntent)

Since: API Level 1

Prepares the intent to launch the ringtone picker. This can be modified to adjust the parameters of the ringtone picker.

Parameters
ringtonePickerIntent The ringtone picker intent that can be modified by putting extras.

protected Uri onRestoreRingtone ()

Since: API Level 1

Called when the chooser is about to be shown and the current ringtone should be marked. Can return null to not mark any ringtone.

By default, this restores the previous ringtone URI from the persistent storage.

Returns
  • The ringtone to be marked as the current ringtone.

protected void onSaveRingtone (Uri ringtoneUri)

Since: API Level 1

Called when a ringtone is chosen.

By default, this saves the ringtone URI to the persistent storage as a string.

Parameters
ringtoneUri The chosen ringtone's Uri. Can be null.

protected void onSetInitialValue (boolean restorePersistedValue, Object defaultValueObj)

Since: API Level 1

Implement this to set the initial value of the Preference.

If restorePersistedValue is true, you should restore the Preference value from the SharedPreferences. If restorePersistedValue is false, you should set the Preference value to defaultValue that is given (and possibly store to SharedPreferences if shouldPersist() is true).

This may not always be called. One example is if it should not persist but there is no default value given.

Parameters
restorePersistedValue True to restore the persisted value; false to use the given defaultValue.
defaultValueObj The default value for this Preference. Only use this if restorePersistedValue is false.