Take audio play in whatsapp as example, if your ear near the phone, the speaker will change to the earphone speaker, while the ear leave the phone, it use the audio speaker.
I am using the mediaplayer to play the audio file, and found that there is
setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
to switch the speaker to the ear speaker. and
setAudioStreamType(AudioManager.STREAM_MUSIC)
for default audio speaker.
The problem is , how to detect when the ear is near the phone, or is it necessary to implement by my program (should have some default android API for that ? )
Thanks a lot for helping