2012-12-08 69 views
1

你好,我不知道如何設置自定義鬧鐘鈴聲。在android中設置自定義鬧鐘鈴聲

這是我的代碼:

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

據工作notications /聲音,但不報警(:S)?

在此先感謝

回答

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);    
    } 
} 
+0

我發現代碼在互聯網上,但它也不工作。 – David

+0

上述設定的鬧鐘鈴聲方法正在工作,但如果您想使用鈴聲,則需要重新發出鬧鈴。 – David

0

試試這個:

Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); 
    playRingtone(RingtoneManager.getRingtone(getApplicationContext(), ringtoneUri)); 

,然後寫另一種方法playRingtone(鈴聲newRingtone)播放鈴聲。

private void playRingtone(Ringtone newRingtone) { 

     if(null != mCurrentRingtone && mCurrentRingtone.isPlaying()) 
      mCurrentRingtone.stop(); 

      mCurrentRingtone = newRingtone; 

     if(null != newRingtone){ 
      mCurrentRingtone.play(); 
     } 
    }