获取Android中可用铃声的列表 [英] Getting a list of available Ringtones in Android

查看:397
本文介绍了获取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.

我发现最近的事情是这里,但这只是为了设置默认铃声。任何想法有谁?它可以进出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.

推荐答案

铃声管理器是您正在寻找的。您只需使用 setType 设置< a href =http://developer.android.com/reference/android/media/RingtoneManager.html#TYPE_RINGTONE =noreferrer> TYPE_RINGTONE ,然后迭代由 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆