开发者

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;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜