【问题标题】:Bluetooth SCO not connecting in Android 12 devices蓝牙 SCO 未在 android 12 设备中连接
【发布时间】: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
}

这是我使用的代码。

    标签: android kotlin bluetooth


    【解决方案1】:

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

    这段代码成功了。

    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
            )
    

    我只需要在主线程中运行 startbluetooth sco。 它开始在 android os 12 设备中正常工作。

    【讨论】:

    • 你能告诉我startBluetoothSco()isBluetoothScoOn = true 之间的区别吗?
    • @SujithManjavana startBluetoothSco() 这用于启动蓝牙服务,而 isBluetoothScoOn 用作标志来检查我是否已经请求启动蓝牙服务
    【解决方案2】:

    请问您的解决方案在哪里添加,我没有阅读

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-21
      • 1970-01-01
      相关资源
      最近更新 更多