1

您好,我想知道如何设置自定义闹钟铃声。

这是我的代码:

RingtoneManager.setActualDefaultRingtoneUri(
                    this,
                    RingtoneManager.TYPE_ALARM,
                    newUri
                    );

它适用于通知/声音但不适用于警报(:S)?

提前致谢

4

2 回答 2

1

你可以使用这个代码

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);               
     }
 }
于 2012-12-08T20:03:33.093 回答
0

试试这个:

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();
        }
    }
于 2015-07-19T06:57:23.327 回答