Reputation: 109
I want to use RingtoneManager
(or create a custom similar class if not possible) to choose one of my custom list of raw files (I want to show only my files not the default list including my files).
I am used to use this way to pick ringtone How to bring up list of available notification sounds on Android but this time I want to show my custom list of ringtones.
Upvotes: 0
Views: 382
Reputation: 7479
If you want to do this in some kind of settings, you can use ListPreference for letting the user choose a melody. Then you just need to populate your preference in your code; you do this in the following manner:
ListPreference listPreference = (ListPreference) findPreference("yourPreferenceName");
//Now you need to retrieve your melodies from res/raw folder and get their names and id's
ListPreference needs two things to function properly: entries, and entry values. Entries are what the user sees when he opens the list (in your case, names of melodies). And the entry values are the values that will be saved in the default SharedPreference (read a little about using preferences from which ListPreference is derived). All you need to do now is to create entries and entryValues:
CharSequence entries = new CharSequence[numberOfMelodies];
CharSequence entryValues = new CharSequence[numberOfMelodies];
And fill them up manually or inside a loop. After that just do
listPreference.setEntries(entries);
listPreference.setEntryValues(entryValues);
And get the selected melody's id from SharedPreference wherever you want in your app and use it. (Preference saves the new selection in the default SharedPreference for you automatically every time, you don't need to worry about that).
Upvotes: 1