播放默认铃声

推荐安卓开发神器(里面有各种UI特效和android代码库实例)

Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); 
 mMediaPlayer = new MediaPlayer();
 mMediaPlayer.setDataSource(this, alert);
 final AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
 if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
            player.setAudioStreamType(AudioManager.STREAM_ALARM);
            player.setLooping(true);
            player.prepare();
            player.start();
  }



会出现 Couldn't open fd for content://settings/system/ringtone但是在真机上是可以的

 

你可能感兴趣的:(java)