我尝试在通话模式下将设备音频设置为扬声器 它在我检查的大多数设备上工作。
我购买了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
答案 0 :(得分:0)
添加<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />