Icemanind
Icemanind

Reputation: 48686

Forcing sound output through speaker in Android

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

Answers (3)

Héctor Quintero
Héctor Quintero

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

Ram
Ram

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

Roman Nurik
Roman Nurik

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

Related Questions