【发布时间】:2022-09-28 14:23:09
【问题描述】:
我仅在 android os 12 设备中的 android 应用程序音频呼叫中有奇怪的问题。
当我在设备中连接蓝牙的情况下拨打电话时,音频正在流动并且我能够在蓝牙设备中听到音频。但是当我尝试在连接的蓝牙设备和扬声器之间切换时,它在 android OS 11 及以下设备中完美运行。
但是对于 android OS 12,它无法正常工作。当我尝试从扬声器切换到蓝牙设备时没有音频。我能够在扬声器中听到声音。
在检查了 android 文档后,我什至添加了代码来询问使用蓝牙连接的权限。
但是仍然尝试在 os 12 设备中切换音频,但仍然没有音频。我知道 os 12 缺少一些东西。
你们能告诉我吗
<!--BLUETOOTH PERMISSION-->
<uses-permission android:name=\"android.permission.BLUETOOTH\" />
<!-- Request legacy Bluetooth permissions on older devices. -->
<uses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\" />
<!-- Needed only if your app looks for Bluetooth devices.
If your app doesn\'t use Bluetooth scan results to derive physical
location information, you can strongly assert that your app
doesn\'t derive physical location. -->
<uses-permission android:name=\"android.permission.BLUETOOTH_SCAN\" />
<!-- Needed only if your app makes the device discoverable to Bluetooth
devices. -->
<uses-permission android:name=\"android.permission.BLUETOOTH_ADVERTISE\" />
<!-- Needed only if your app communicates with already-paired Bluetooth
devices. -->
<uses-permission android:name=\"android.permission.BLUETOOTH_CONNECT\" />
我仍然很困惑我是否错过了 android os 12,因为音频清晰流畅,并且我能够在 os 11 和以下设备之间切换。
fun startScoAudio(): Boolean {
ThreadUtils.checkIsOnMainThread()
if (scoConnectionAttempts >= MAX_SCO_CONNECTION_ATTEMPTS) {
return false
}
if (bluetoothState != BluetoothState.HEADSET_AVAILABLE) {
return false
}
bluetoothState = BluetoothState.SCO_CONNECTING
audioManager?.startBluetoothSco()
audioManager?.isBluetoothScoOn = true
scoConnectionAttempts++
startTimer()
return true
}
这是我使用的代码。