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?