我想为Android开发一个警报应用程序,我想使用Android的默认警报声音列表,并让用户在新对话框中从列表中选择警报声音。我可以通过以下代码使用默认警报声音:
Uri alarm = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
MediaPlayer mp = MediaPlayer.create(getApplicationContext(), alarm);
mp.start();
最佳答案
请尝试这个
public void getRingtones( )
{
RingtoneManager ringtoneMgr = new RingtoneManager(this);
ringtoneMgr.setType(RingtoneManager.TYPE_ALL);
Cursor alarmsCursor = ringtoneMgr.getCursor();
int alarmsCount = alarmsCursor.getCount();
if (alarmsCount == 0 && !alarmsCursor.moveToFirst())
{
}
else
{
ringtonesStrings = new String[alarmsCount];
ringtonesUris = new String[alarmsCount];
while(!alarmsCursor.isAfterLast() && alarmsCursor.moveToNext()) {
int currentPosition = alarmsCursor.getPosition();
rintonesStrings[currentPosition] = ringtoneMgr.getRingtone(currentPosition).getTitle(getApplicationContext());
ringtonesUris[currentPosition] = ringtoneMgr.getRingtoneUri(currentPosition).toString();
}
//alarmsCursor.close();
}
}