我试图在通话模式下将设备音频设置为扬声器。
它适用于我检查过的大多数设备。
我购买了 OnePlus5 设备,但它无法使用。
final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.stopBluetoothSco();
audioManager.setBluetoothScoOn(false);
audioManager.setSpeakerphoneOn(true);
当我检查结果为假时:
audioManager.isSpeakerphoneOn() // return false
正如我在 logcat 中看到的,当我从本机拨号器设置扬声器时,它们使用一些不同的对象来设置扬声器:
08-14 09:53:39.778 1562-2928/? I/Telecom: CallAudioRouteStateMachine: Message received: USER_SWITCH_SPEAKER=1104, arg1=0: ICA.sAR->CARSM.pM_USER_SWITCH_SPEAKER@COs_0
08-14 09:53:39.778 836-14835/? D/AudioPolicyManagerCustom: getOutputForDevice() returns output 13 flag 2
08-14 09:53:39.778 1562-2928/? I/Telecom: Event: Call TC@22: AUDIO_ROUTE, Leaving state ActiveEarpieceRoute: ICA.sAR->CARSM.pM_USER_SWITCH_SPEAKER@COs_0
08-14 09:53:39.778 1562-2928/? I/Telecom: Event: Call TC@22: AUDIO_ROUTE, Entering state ActiveSpeakerRoute: ICA.sAR->CARSM.pM_USER_SWITCH_SPEAKER@COs_0
08-14 09:53:39.778 836-1095/? D/APM_AudioPolicyManager: startOutput() output 13, stream 1, session 25
08-14 09:53:39.778 1562-2928/? I/Telecom: CallAudioRouteStateMachine: turning speaker phone true: ICA.sAR->CARSM.pM_USER_SWITCH_SPEAKER@COs_0
08-14 09:53:39.778 836-1095/? D/AudioPolicyManagerCustom: getNewOutputDevice() selected device 1
08-14 09:53:39.778 836-1095/? D/APM_AudioPolicyManager: setOutputDevice() device 0001 delayMs 0
08-14 09:53:39.779 836-1095/? D/APM_AudioPolicyManager: startOutput()--
08-14 09:53:39.779 1562-2928/? V/AudioManager: Elem: dalvik.system.VMStack.getThreadStackTrace(Native Method)
08-14 09:53:39.779 1562-2928/? V/AudioManager: Elem: java.lang.Thread.getStackTrace(Thread.java:1566)
08-14 09:53:39.779 1562-2928/? V/AudioManager: Elem: android.media.AudioManager.setSpeakerphoneOn(AudioManager.java:1286)
08-14 09:53:39.779 1562-2928/? V/AudioManager: Elem: com.android.server.telecom.CallAudioRouteStateMachine.setSpeakerphoneOn(CallAudioRouteStateMachine.java:1353)
08-14 09:53:39.779 1562-2795/? D/VibratorService: timeout: 0, startTime: 6699313, pattern: [0, 10], vibrateIntensity: Middle, repeat: -1, usageHint: 13, uid: 1001, opPkg: com.android.incallui
[ 08-14 09:53:39.780 1562: 8387 E/ ]
Vibrator on : 10