我有奇怪的问题,在android应用程序音频调用,只有在android操作系统12设备。当im在设备中使用蓝牙进行呼叫时,当我试图在连接的蓝牙设备和扬声器之间切换时,音频是流动的,im能够在蓝牙device.But中听到音频,它在android 11及以下设备上工作得很好。
但是对于android 12来说,当我试图从响亮的speaker.im切换到蓝牙设备时,它不能工作的speaker.im就不是音频了,它能够在扬声器中听到声音。
在检查了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" />
我仍然很困惑,我是否错过了安卓操作系统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
}
这是我用过的代码。
发布于 2022-04-13 14:06:58
在开源项目中搜索了一些代码之后。
这段代码起了作用。
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设备上正常工作。
https://stackoverflow.com/questions/71797155
复制相似问题