Android之开启手机系统自带铃声

时间:2024-05-21 10:03:38
 /**
* 开启手机系统自带铃声
*/
private void startAlarm() {
mMediaPlayer = MediaPlayer.create(this, getSystemDefultRingtoneUri());
mMediaPlayer.setLooping(true);
try {
mMediaPlayer.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mMediaPlayer.start();
} private void stopAlarm(){
mMediaPlayer.stop();
} /**
* 获取系统自带铃声的uri
* @return RingtoneManager.getActualDefaultRingtoneUri(this,
RingtoneManager.TYPE_RINGTONE)
*/
private Uri getSystemDefultRingtoneUri() {
return RingtoneManager.getActualDefaultRingtoneUri(this,
RingtoneManager.TYPE_RINGTONE);
}