您好,我想知道如何设置自定义闹钟铃声。
这是我的代码:
RingtoneManager.setActualDefaultRingtoneUri(
this,
RingtoneManager.TYPE_ALARM,
newUri
);
它适用于通知/声音但不适用于警报(:S)?
提前致谢
你可以使用这个代码
Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
if(alert == null){
// alert is null, using backup
alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if(alert == null){ // I can't see this ever being null (as always have a default notification) but just incase
// alert backup is null, using 2nd backup
alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
}
}
试试这个:
Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
playRingtone(RingtoneManager.getRingtone(getApplicationContext(), ringtoneUri));
然后,编写另一个方法playRingtone(Ringtone newRingtone)来播放铃声。
private void playRingtone(Ringtone newRingtone) {
if(null != mCurrentRingtone && mCurrentRingtone.isPlaying())
mCurrentRingtone.stop();
mCurrentRingtone = newRingtone;
if(null != newRingtone){
mCurrentRingtone.play();
}
}