RingtonePreference
public
class
RingtonePreference
extends Preference
implements
PreferenceManager.OnActivityResultListener
java.lang.Object | ||
↳ | android.preference.Preference | |
↳ | android.preference.RingtonePreference |
This class was deprecated
in API level 29.
Use the AndroidX
Preference Library for consistent behavior across all devices. For more information on
using the AndroidX Preference Library see
Settings.
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
System#DEFAULT_RINGTONE_URI
,
System#DEFAULT_NOTIFICATION_URI
, or
System#DEFAULT_ALARM_ALERT_URI
. If the user chooses the "Silent"
item, the saved string will be an empty string.
Summary
XML attributes | ||
---|---|---|
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'. |
Inherited XML attributes | |
---|---|
Inherited constants |
---|
Public constructors | |
---|---|
RingtonePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
|
|
RingtonePreference(Context context, AttributeSet attrs, int defStyleAttr)
|
|
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. |
Inherited methods | |
---|---|
XML attributes
android:ringtoneType
Which ringtone type(s) to show in the picker.
Must be one or more (separated by '|') of the following constant values.
Constant | Value | Description |
---|---|---|
alarm | 4 | Alarm sounds. |
all | 7 | All available ringtone sounds. |
notification | 2 | Notification sounds. |
ringtone | 1 | Ringtones. |
android:showDefault
Whether to show an item for a default sound.
May be a boolean value, such as "true
" or
"false
".
android:showSilent
Whether to show an item for 'Silent'.
May be a boolean value, such as "true
" or
"false
".
Public constructors
RingtonePreference
public RingtonePreference (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
defStyleAttr |
int |
defStyleRes |
int |
RingtonePreference
public RingtonePreference (Context context, AttributeSet attrs, int defStyleAttr)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
defStyleAttr |
int |
RingtonePreference
public RingtonePreference (Context context, AttributeSet attrs)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
RingtonePreference
public RingtonePreference (Context context)
Parameters | |
---|---|
context |
Context |
Public methods
getRingtoneType
public int getRingtoneType ()
Returns the sound type(s) that are shown in the picker.
Returns | |
---|---|
int |
The sound type(s) that are shown in the picker. |
See also:
getShowDefault
public boolean getShowDefault ()
Returns whether to a show an item for the default sound/ringtone.
Returns | |
---|---|
boolean |
Whether to show an item for the default sound/ringtone. |
getShowSilent
public boolean getShowSilent ()
Returns whether to a show an item for 'Silent'.
Returns | |
---|---|
boolean |
Whether to show an item for 'Silent'. |
onActivityResult
public boolean onActivityResult (int requestCode, int resultCode, Intent data)
See Activity's onActivityResult.
Parameters | |
---|---|
requestCode |
int |
resultCode |
int |
data |
Intent |
Returns | |
---|---|
boolean |
Whether the request code was handled (in which case subsequent listeners will not be called. |
setRingtoneType
public void setRingtoneType (int type)
Sets the sound type(s) that are shown in the picker.
Parameters | |
---|---|
type |
int : The sound type(s) that are shown in the picker. |
See also:
setShowDefault
public void setShowDefault (boolean showDefault)
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 |
boolean : Whether to show the default or not. |
setShowSilent
public void setShowSilent (boolean showSilent)
Sets whether to show an item for 'Silent'.
Parameters | |
---|---|
showSilent |
boolean : Whether to show 'Silent'. |
Protected methods
onAttachedToHierarchy
protected void onAttachedToHierarchy (PreferenceManager preferenceManager)
Called when this Preference has been attached to a Preference hierarchy. Make sure to call the super implementation.
Parameters | |
---|---|
preferenceManager |
PreferenceManager : The PreferenceManager of the hierarchy. |
onClick
protected void onClick ()
Processes a click on the preference. This includes saving the value to
the SharedPreferences
. However, the overridden method should
call callChangeListener(java.lang.Object)
to make sure the client wants to
update the preference's state with the new value.
onGetDefaultValue
protected Object onGetDefaultValue (TypedArray a, int index)
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 TypedArray#getString(int)
.
Parameters | |
---|---|
a |
TypedArray : The set of attributes. |
index |
int : The index of the default value attribute. |
Returns | |
---|---|
Object |
The default value of this preference type. |
onPrepareRingtonePickerIntent
protected void onPrepareRingtonePickerIntent (Intent ringtonePickerIntent)
Prepares the intent to launch the ringtone picker. This can be modified to adjust the parameters of the ringtone picker.
Parameters | |
---|---|
ringtonePickerIntent |
Intent : The ringtone picker intent that can be
modified by putting extras. |
onRestoreRingtone
protected Uri onRestoreRingtone ()
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 | |
---|---|
Uri |
The ringtone to be marked as the current ringtone. |
onSaveRingtone
protected void onSaveRingtone (Uri ringtoneUri)
Called when a ringtone is chosen.
By default, this saves the ringtone URI to the persistent storage as a string.
Parameters | |
---|---|
ringtoneUri |
Uri : The chosen ringtone's Uri . Can be null. |
onSetInitialValue
protected void onSetInitialValue (boolean restorePersistedValue, Object defaultValueObj)
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).
In case of using PreferenceDataStore
, the restorePersistedValue is
always true
. But the default value (if provided) is set.
This may not always be called. One example is if it should not persist but there is no default value given.
Parameters | |
---|---|
restorePersistedValue |
boolean : True to restore the persisted value;
false to use the given defaultValue. |
defaultValueObj |
Object : The default value for this Preference. Only use this
if restorePersistedValue is false. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.