public static void PlayAlarmRing(Context mContext) { Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); try { MediaPlayer mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(mContext, alert); final AudioManager audioManager = (AudioManager) mContext .getSystemService(Context.AUDIO_SERVICE); if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) { mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); mMediaPlayer.setLooping(false); mMediaPlayer.prepare(); mMediaPlayer.start(); } } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
无视手机的静音模式