Android 14 蓝牙主从模式切换

切换蓝牙的A2DP(高级音频分布配置文件)和AVRCP(音频/视频远程控制配置文件)的源(source)和汇点(sink)模式。

这里,SystemProperties.get尝试获取bluetooth.profile.a2dp.sink.enabled属性的值。如果该属性不存在,它将返回默认值"false"。然后,它检查这个值是否等于"true"。

  1. 如果当前是A2DP Sink模式(即isA2dpSink为true):
复制代码

java复制代码

|---|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| | if(isA2dpSink){ |
| | // 切换成A2DP Source和AVRCP Target模式 |
| | SystemProperties.set("bluetooth.profile.a2dp.sink.enabled","false"); SystemProperties.set("bluetooth.profile.avrcp.controller.enabled","false"); SystemProperties.set("bluetooth.profile.a2dp.source.enabled","true"); SystemProperties.set("bluetooth.profile.avrcp.target.enabled","true"); |
| | } |

代码试图切换到A2DP Source和AVRCP Target模式。

  1. 如果当前不是A2DP Sink模式(即isA2dpSink为false):
复制代码

java复制代码

|---|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| | else{ |
| | // 这里也写着"切换成主模式",但实际上是切换回A2DP Sink和AVRCP Controller模式 |
| | SystemProperties.set("bluetooth.profile.a2dp.sink.enabled","true"); SystemProperties.set("bluetooth.profile.avrcp.controller.enabled","true"); SystemProperties.set("bluetooth.profile.a2dp.source.enabled","false"); SystemProperties.set("bluetooth.profile.avrcp.target.enabled","false"); |
| | } |

但是,这里的注释还是写着"切换成主模式",但实际上它是将蓝牙设置切换回A2DP Sink和AVRCP Controller模式。

修改建议:

  1. 修正注释以更准确地描述代码的功能。

  2. 考虑到代码可能在一个上下文中运行,其中A2DP Source和AVRCP Target被认为是"主模式",而A2DP Sink和AVRCP Controller被认为是"从模式"。如果是这样,那么注释应该是这样的:

java 复制代码
       boolean isA2dpSink = SystemProperties.get("bluetooth.profile.a2dp.sink.enabled","false").equals("true");

        if(isA2dpSink){//切换成主模式
            SystemProperties.set("bluetooth.profile.a2dp.sink.enabled","false");
            SystemProperties.set("bluetooth.profile.avrcp.controller.enabled","false");
            SystemProperties.set("bluetooth.profile.a2dp.source.enabled","true");
            SystemProperties.set("bluetooth.profile.avrcp.target.enabled","true");
        }else{//切换成主模式
            SystemProperties.set("bluetooth.profile.a2dp.sink.enabled","true");
            SystemProperties.set("bluetooth.profile.avrcp.controller.enabled","true");
            SystemProperties.set("bluetooth.profile.a2dp.source.enabled","false");
            SystemProperties.set("bluetooth.profile.avrcp.target.enabled","false");
        }
相关推荐
waynaqua1 分钟前
FastAPI开发AI应用一:实现连续多轮对话
python·openai
纨妙5 分钟前
python打卡day59
开发语言·python
waynaqua5 分钟前
FastAPI开发AI应用二:多厂商模型使用指南
python·openai
秋难降9 分钟前
Python 知识 “八股”:给有 C 和 Java 基础的你😁😁😁
java·python·c
wuxuanok11 分钟前
Web后端开发-请求响应
java·开发语言·笔记·学习
FF-Studio22 分钟前
大语言模型(LLM)课程学习(Curriculum Learning)、数据课程(data curriculum)指南:从原理到实践
人工智能·python·深度学习·神经网络·机器学习·语言模型·自然语言处理
Sally璐璐31 分钟前
IPSAN 共享存储详解:架构、优化与落地实践指南
开发语言·php
像风一样的男人@41 分钟前
python --货车装厢问题
开发语言·python
Humbunklung1 小时前
Rust枚举:让数据类型告别单调乏味
开发语言·后端·rust
Y1nhl1 小时前
力扣_链表_python版本
开发语言·python·算法·leetcode·链表·职场和发展