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.
Asked
Active
Viewed 1.2k times
3 Answers
4
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.

Roman Nurik
- 29,665
- 7
- 84
- 82
-
@Icemanind have you tried it this way? In most of the times you don't won't to disobey user settings like playing sound through headphones. But if your usecase is valid this sounds like it would work. – Janusz Jun 01 '10 at 15:21
-
1Yeah. What I was trying to do was create an alarm clock program for my own use for my own android phone. Sometimes though, I accidently forget to unplug my earphones and the alarm will go off through the earphones and I will not hear them. That is why I was wondering how to do this. – Icemanind Jun 01 '10 at 16:07
2
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);

Héctor Quintero
- 75
- 5
-
Android studio says this is a "wrong constant". But with ` m_amAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION)` it works. – Luis A. Florit May 23 '22 at 19:41
-
`MODE_IN_COMMUNICATION` is the same as `MODE_RINGTONE | MODE_IN_CALL` => `0x03 == 0x01 | 0x02` – mortalis Jan 17 '23 at 22:19
-
Thanks for the permission part! 'Cause other answers I found did not mentions that and the `setMode` had no effect. – mortalis Jan 17 '23 at 22:22
1
Sound output through speaker
AudioManager m_amAudioManager =
AudioManager)getSystemService(Context.AUDIO_SERVICE);
m_amAudioManager.setMode(AudioManager.MODE_NORMAL);
m_amAudioManager.setSpeakerphoneOn(true);

Melquiades
- 8,496
- 1
- 31
- 46

Ram
- 1,408
- 13
- 29
-
1doesn't work for HTC M9 and nexus devices :(, any alternate solutions ?? – Rahul Baradia Aug 17 '15 at 13:09
-
Doesn't work for Galaxy Note 10 either. But with `m_amAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION)` it works. – Luis A. Florit May 23 '22 at 19:58