2016-03-03 34 views
0

我想覆蓋靜音模式,使手機廣播一個謹慎的聲音或類似的東西。我怎樣才能以簡單的方式做到這一點?我想我需要使用AudioManager,但我不確定。Overide Silent模式

回答

0

你是正確的,你需要得到的音頻管理器,像這樣

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