I need to play some audio through the earpiece. I am using AudioTrack to play some sound on a device. and the audio mode is set as STREAM_VOICE_CALL. Also, in my activity, the speakerphone is turned off by:
AudioManager am;
am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.setSpeakerphoneOn(false);
This seems to work perfectly on 2.3 devices. But on 2.1, sound is still played from the speaker.
As a fix for this, I tried using setMode() as:
am.setMode(AudioManager.MODE_IN_CALL);
With this, the sound was played through the earpiece for 2.1 and 2.3, but most times not played at all by 2.3. Also, I read at some places that the setMode() should not be used by apps as it affects the system-wide phone state. here : http://code.google.com/p/sipdroid/issues/detail?id=270
Any help?
Below 2.3, Android has been a little buggy with
setSpeakerPhoneOn()
. As per this answer, I think you'll need to use both API methods.In regards to 2.3 audio not being played at all, check your in-call volume settings (which is what will be used). Try and keep track of the state the phone was in before using
setMode()
as well, perhaps setting it back toMODE_NORMAL
once the audio manager is no longer being used.