首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >蓝牙SCO不连接android 12设备

蓝牙SCO不连接android 12设备
EN

Stack Overflow用户
提问于 2022-04-08 12:39:07
回答 1查看 506关注 0票数 1

我有奇怪的问题,在android应用程序音频调用,只有在android操作系统12设备。当im在设备中使用蓝牙进行呼叫时,当我试图在连接的蓝牙设备和扬声器之间切换时,音频是流动的,im能够在蓝牙device.But中听到音频,它在android 11及以下设备上工作得很好。

但是对于android 12来说,当我试图从响亮的speaker.im切换到蓝牙设备时,它不能工作的speaker.im就不是音频了,它能够在扬声器中听到声音。

在检查了android文档之后,我甚至添加了代码,请求允许使用蓝牙连接。

但是仍然尝试在os 12设备上切换音频,仍然没有声音,我知道os 12缺少一些东西。

你们能不能告诉我

代码语言:javascript
复制
<!--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" />

我仍然很困惑,我是否错过了安卓操作系统12,因为音频显然是流动的,我能够在os 11和更低的设备之间切换。

代码语言:javascript
复制
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
}

这是我用过的代码。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-13 14:06:58

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

这段代码起了作用。

代码语言:javascript
复制
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操作系统12设备上正常工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71797155

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档