Route audio via speaker when headphone plugged it
How we can route audio output via speaker even when the headset is plugged in?
My code:
if(audioManager.isWiredHeadsetOn())
{
audioManager.setWiredHeadsetOn(false);
audioManager.setSpeakerphoneOn(true);
audioManager.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
audioManager.setMode(AudioManager.MODE_NORMAL);
开发者_JS百科 }
Am I missing something here?
Did you try adding <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
to your AndroidManifest.xml ?
http://developer.android.com/reference/android/Manifest.permission.html#MODIFY_AUDIO_SETTINGS
The method AudioManager.setRouting()
is depreciated.
From the Javadoc:
Do not set audio routing directly, use
setSpeakerphoneOn()
,setBluetoothScoOn()
methods instead.
maybe you need to audioManager.setMode(AudioManager.MODE_IN_CALL) or MODE_IN_COMMUNICATION;
精彩评论