如何在通话期间通过代码启用 Android 扬声器? [英] How do I enable the Android speaker during a call, from code?

查看:30
本文介绍了如何在通话期间通过代码启用 Android 扬声器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题之前已在此站点上提出并回答过两次,但该代码似乎根本不适用于现代手机.我正在使用 Android 4.2 和 Android 4.3,但似乎都不起作用.

This question has been asked and answered twice before on this site, but that code doesn't seem to work on modern phones at all. I'm working on an Android 4.2 and an Android 4.3 and neither seems to work.

我在通话过程中通过媒体播放器播放 MP3,效果很好,但歌曲和通话都是通过语音扬声器传来的.如果我按扬声器",它们都会继续通过扬声器播放.我需要那种效果,但不必自己按下

I am playing an MP3 through a Media Player during the call, and it works fine, but both the song and the call are coming through the voice speaker. If I press "Speaker" they both continue playing through the loudspeaker. I need that effect, but without having to press it myself

    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    audioManager.setMode(AudioManager.MODE_IN_CALL);
    audioManager.setSpeakerphoneOn(true);

     <uses-permission android:name="android.permission.RECORD_AUDIO" />
     <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>

有人建议将此作为解决 S.O 的其他两个问题的解决方案,但它根本不起作用.它应该,代码很好,但它根本对音频没有任何作用.

This was suggested as a solution to both other questions on S.O, but it simply doesn't work. It should, the code is fine, but it simply does nothing to the audio at all.

想法?

推荐答案

我解决了.我创建了一个线程,在While (true)"中不断运行上述三行代码.效果很好.

I solved it. I created a thread that constantly runs the above three lines of code in a "While (true)". Works great.

这篇关于如何在通话期间通过代码启用 Android 扬声器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆