2

我要做的是从我的应用程序拨打电话并在此通话中打开扬声器。

在 android 4.0 上一切正常,我刚刚在开始呼叫意图之前设置了 audiomanager.setSpeakerphoneOn(true) 。

但在 android 4.1 PhoneUtils 在通话前检查扬声器状态并将其关闭(logcat):

D/PhoneUtils( 1029): about to activate speaker
D/PhoneUtils( 1029): activateSpeakerIfDocked()...
I/PhoneUtils( 1029): Forcing speaker off when initiating a new outgoing call...

我还尝试使用以下方法监听呼叫状态: mTelephonyManager.listen(receiver, PhoneStateListener.LISTEN_CALL_STATE); 在此接收器之后将捕获 3 个状态:

  • IDLE(我不感兴趣)
  • CALL_STATE_RINGING(也没有兴趣,因为我需要处理拨出电话)
  • CALL_STATE_OFFHOOK(虽然这个会有所帮助)

但是最后一个“事件”也在PhoneUtils检查扬声器状态(logcat)之前发送:

11:43:48.089 D/KeyguardViewMediator( 665): keyguard receiver action : android.intent.action.PHONE_STATE
11:43:48.089 D/KeyguardViewMediator( 665): keyguard receiver TelephonyManager.EXTRA_STATE : OFFHOOK
11:43:48.099 D/PhoneUtils( 977): setAudioMode()...OFFHOOK
11:43:48.099 D/MyPhoneStateListener:main( 2590): catching call state CALL_STATE_OFFHOOK
11:43:48.099 D/MyPhoneStateListener:main( 2590): turning phone speaker on
...
11:43:48.119 D/PhoneUtils( 977): about to activate speaker
11:43:48.119 I/PhoneUtils( 977): Forcing speaker off when initiating a new outgoing call...

如果有人面临同样的问题或有解决方案?

谢谢!

4

1 回答 1

1

我这周遇到了这个问题。。

阅读果冻豆代码源,我找到了这段代码

// This is not an error but might cause users' confusion. Add log just in case.
Log.i(LOG_TAG, "Forcing speaker off when initiating a new outgoing call...");    
PhoneUtils.turnOnSpeaker(app, false, true);

就是这样,在 4.1 版中,android 在来电和去电中强制扬声器关闭。我的解决方案是在我的通话状态广播接收器中打开扬声器,然后开始拨打电话

于 2012-12-19T11:34:50.767 回答