Android 5.0+ AudioManager setMode not working
I am working on AudioManager which is Android SystemService. with Android System 5.0+, I am facing an issue where AudioManager's setMode method is not working.
i via test, Android M, Lollipop .. 5.0+ version, AudioManager setMode doesn't work. Example:
public void initAudioImageIcon(boolean initLoad) {
boolean isAudioHeaderMode = IMSharedPreferences.getBooleanExtra(this, IMSPConstant.SP_NAME_MESSAGE,
IMSPConstant.SP_KEY_AUDIO_HEADER_MODE);
if (isAudioHeaderMode) {
mAudioHanderMode.setVisibility(View.VISIBLE);
// audioManager.setMode(AudioManager.MODE_IN_CALL) , but android system 5.0+ no any change, getMode() == AudioManager.MODE_NORMAL
setAudioMode(AudioManager.MODE_IN_CALL);
audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL);
if (!initLoad) {
showAudioModePrompt(this.getText(R.string.im_audio_in_call), 1000);
}
} else {
mAudioHanderMode.setVisibility(View.GONE);
setAudioMode(AudioManager.MODE_NORMAL);
if (!initLoad) {
showAudioModePrompt(this.getText(R.string.im_audio_in_speeker), 1000);
}
}
}
but Android 3.0+, 4.0+ is ok, only 5.0+. therefore, I don't know where the errors are occurring.
+3
source to share
2 answers
With audio mode set to:
setMode(AudioManager.MODE_IN_COMMUNICATION);
setSpeakerphoneOn(false);
while my audio stream is set to STREAM_MUSIC, I can route audio to headphones easily. I tested it myself in AOSP Lollipop code.
Here in the question you never talked about the type of your stream. Set the stream to STREAM_MUSIC or STREAM_VOICE_CALL and the code will work for you too.
+4
source to share