how to turn speaker on/off programmatically in android Pie and UP

后端 未结 3 1741
你的背包
你的背包 2021-02-14 18:40

Same as this question and many others from a few years ago: how to turn speaker on/off programmatically in android 4.0

It seems that Android has changed the way it handl

相关标签:
3条回答
  • 2021-02-14 18:46

    For this problem please try the following code it is working for me.

    AudioManager myAudioManager;
    myAudioManager.setMode(AudioManager.MODE_NORMAL);
    myAudioManager.setSpeakerphoneOn(true);
    
    0 讨论(0)
  • 2021-02-14 19:00

    In Android Pie, I had the same problem. I resolved it using an InCallService with

    setAudioRoute(ROUTE_SPEAKER)
    

    Your app needs to be Default phone app.

    0 讨论(0)
  • 2021-02-14 19:09

    try this:

        AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
        audioManager.setMode(AudioManager.STREAM_MUSIC);
        audioManager.setSpeakerphoneOn(true);
    
    0 讨论(0)
提交回复
热议问题