获取可用的铃声在Android的清单 [英] Getting a list of available Ringtones in Android
问题描述
我见过很多的如何设置默认铃声的例子,但是我更感兴趣的是能够填充下拉填充在手机上可用的铃声框列表。于是人们看到,当他们改变自己的铃声在android设置列表中,我希望能够列出所有这些的。
I've seen plenty of examples of how to set a default ringtone, but what I'm more interested in is being able populate a drop down box list filled with the available ringtones on the phone. So the list that people see when they change their ringtone in the android settings, I want to be able to list all of those.
我发现的最接近的是<一个href=\"http://stackoverflow.com/questions/1271777/how-to-set-ringtone-in-android-from-my-activity\">here,但同样,这只是用于设置默认铃声。任何想法吗?它可以是或缩小ringtonemanager的。
The closest thing I've found is here, but again this is just for setting the default ringtone. Any ideas anyone? It can be in or out of ringtonemanager.
推荐答案
RingtoneManager 是什么您正在寻找。你只需要使用<一个href=\"http://developer.android.com/reference/android/media/RingtoneManager.html#setType%28int%29\">setType设置<一个href=\"http://developer.android.com/reference/android/media/RingtoneManager.html#TYPE_RINGTONE\">TYPE_RINGTONE然后遍历由<提供的光标href=\"http://developer.android.com/reference/android/media/RingtoneManager.html#getCursor%28%29\">getCursor.
RingtoneManager is what you are looking for. You just need to use setType to set TYPE_RINGTONE and then iterate over the Cursor provided by getCursor.
这是返回URI的数组,它的寻找报警的铃声,而不是唯一的细微差别的假设方法的工作示例:
This is a working example of an hypothetical method that returns an array of URIs, with the only slight difference that it's looking for alarms instead of ringtones:
RingtoneManager ringtoneMgr = new RingtoneManager(this);
ringtoneMgr.setType(RingtoneManager.TYPE_ALARM);
Cursor alarmsCursor = ringtoneMgr.getCursor();
int alarmsCount = alarmsCursor.getCount();
if (alarmsCount == 0 && !alarmsCursor.moveToFirst()) {
return null;
}
Uri[] alarms = new Uri[alarmsCount];
while(!alarmsCursor.isAfterLast() && alarmsCursor.moveToNext()) {
int currentPosition = alarmsCursor.getPosition();
alarms[currentPosition] = ringtoneMgr.getRingtoneUri(currentPosition);
}
alarmsCursor.close();
return alarms;
这篇关于获取可用的铃声在Android的清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!