private void PlayAlarmRing(){
Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);try{mMediaPlayer = new MediaPlayer();mMediaPlayer.setDataSource(this, alert);final AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);mMediaPlayer.setLooping(true);mMediaPlayer.prepare();}}catch (IllegalStateException e) {e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }mMediaPlayer.start();} private void StopAlarmRing(){mMediaPlayer.stop();} 在andorid模拟器上可能会出现 Couldn''t open fd for content://settings/system/ringtone 但是在真机上是可以的