android 12 台设备中的蓝牙 SCO 未连接

Bluetooth SCO not connecting in android 12 devices

我只在 android os 12 台设备的 android 应用音频通话中遇到奇怪的问题。 当我使用设备中连接的蓝牙拨打电话时,音频正在流动并且无法在蓝牙中听到音频 device.But 当我尝试在连接的蓝牙设备和扬声器之间切换时,它在 android OS 11 及以下设备。
但是对于 android OS 12 它不工作 correctly.there 当我试图从大声切换到蓝牙设备时没有音频 speaker.im 能够在扬声器中听到声音。

检查 android 文档后,我什至添加了代码以请求使用蓝牙连接的权限。
但仍在尝试切换 os 12 台设备的音频仍然没有 audio.I 明白 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
}

这是我用过的代码。

在开源项目中搜索了一些代码后。

这段代码成功了。

Handler(Looper.getMainLooper()).postDelayed(
            {
                /* Sometimes bluetooth sco not starting in some devices immediately
                 so giving a delay and running it main thread */
                audioManager?.startBluetoothSco()
                audioManager?.isBluetoothScoOn = true
                scoConnectionAttempts++
                startTimer()
            }, 500
        )

我所需要的只是 运行 在主线程中启动蓝牙 sco。 它开始在 android os 12 台设备上正常工作。