覆盖静默模式

时间:2016-03-03 15:23:43

标签: android android-studio

我想覆盖静音模式,让手机播放一种谨慎的声音或类似的声音。我怎么能以简单的方式做到这一点?我想我需要使用AudioManager,但我不确定。

1 个答案:

答案 0 :(得分:1)

你是对的,你需要得到像这样的音频管理器

AudioManager audioM = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);

要覆盖静音模式,请使用此

myAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);

然后播放像这样的离散音频文件

MediaPlayer mp = MediaPlayer.create(this, R.raw.yourdiscretesound);
mp.start();

或者使用铃声管理器获得更响亮的声音

int volume = audioM.getStreamMaxVolume(AudioManager.STREAM_ALARM);
audioM.setStreamVolume(AudioManager.STREAM_ALARM,volume,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);

theSound = RingtoneManager.getRingtone(getApplicationContext(),Uri.parse(pathtoyourringtone));

if(theSound!=null){
    theSound.setStreamType(AudioManager.STREAM_ALARM);
    theSound.play();
}

相关:查看here以获取有关AudioManager的教程

相关问题