Reputation: 48686
Is there a way in Android to force output through the phone speaker, even if a headphone is plugged into the jack? I know there has to be a way because when you are talking on the phone, you can put someone on speaker phone, even if there is headphones plugged into the jack.
Upvotes: 10
Views: 13375
Reputation: 95
This worked for me
First, I Added permissions in Manifest.xml
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
Then, I used this code
AudioManager m_amAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
m_amAudioManager.setMode(AudioManager.MODE_RINGTONE | AudioManager.MODE_IN_CALL);
m_amAudioManager.setSpeakerphoneOn(true);
Upvotes: 2
Reputation: 1428
Sound output through speaker
AudioManager m_amAudioManager =
AudioManager)getSystemService(Context.AUDIO_SERVICE);
m_amAudioManager.setMode(AudioManager.MODE_NORMAL);
m_amAudioManager.setSpeakerphoneOn(true);
Upvotes: 1
Reputation: 29745
You can change this system-wide using the AudioManager.setSpeakerphoneOn
method.
I don't believe you can set this for a particular MediaPlayer
/AudioTrack
/SoundPool
instance, but depending on your use case, you might actually be looking to set your audio stream type using MediaPlayer.setAudioStreamType
or an equivalent for other audio playback classes.
Upvotes: 4