当前位置: 首页 > news >正文

Android16 蓝牙打开时,状态栏显示蓝牙图标

说明

本修改主要针对 Android 16(API 36)AOSP 源码中的 SystemUI 模块。

项目内容
适用版本Android 16(API 36)
涉及模块frameworks/base/packages/SystemUI
修改类PhoneStatusBarPolicy
修改方法updateBluetooth()

在 Android 16 原生 SystemUI 中,PhoneStatusBarPolicy.updateBluetooth()默认仅在蓝牙已连接且满足音频 Profile 条件时才显示状态栏图标。用户仅打开蓝牙开关、尚未连接设备时,状态栏不会出现蓝牙图标,与快捷设置中蓝牙已开启的状态不一致。

本次修改在 Android 16 上实现:

  • 蓝牙开启即显示stat_sys_data_bluetooth图标(新增资源)
  • 蓝牙已连接时切换为stat_sys_data_bluetooth_connected图标
  • 蓝牙关闭时隐藏图标

若移植到其他 Android 版本,需确认对应分支中PhoneStatusBarPolicy.java路径及updateBluetooth()实现是否一致,资源命名是否相同。


修改文件

frameworks/base/packages/SystemUI/res/drawable/stat_sys_data_bluetooth.xml (新增) frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java (修改)

1. 新增stat_sys_data_bluetooth.xml

路径:frameworks/base/packages/SystemUI/res/drawable/stat_sys_data_bluetooth.xml

<!-- Copyright (C) 2017 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --><vectorxmlns:android="http://schemas.android.com/apk/res/android"android:width="17dp"android:height="17dp"android:viewportWidth="17.0"android:viewportHeight="17.0"><groupandroid:translateY="0.5"android:translateX="0.5"><pathandroid:pathData="M8.84,8l2.62,-2.62c0.29,-0.29 0.29,-0.75 0,-1.04L8.33,1.22L8.31,1.2c-0.3,-0.28 -0.76,-0.26 -1.03,0.04c-0.13,0.13 -0.2,0.31 -0.2,0.5v4.51L4.24,3.4c-0.29,-0.29 -0.74,-0.29 -1.03,0s-0.29,0.74 0,1.03L6.78,8l-3.56,3.56c-0.29,0.29 -0.29,0.74 0,1.03s0.74,0.29 1.03,0l2.83,-2.83v4.51c0,0.4 0.33,0.73 0.73,0.73c0.18,0 0.36,-0.07 0.5,-0.2l0.03,-0.03l3.12,-3.12c0.29,-0.29 0.29,-0.75 0,-1.04L8.84,8zM8.47,6.37V3.36l1.5,1.5L8.47,6.37zM8.47,12.63V9.62l1.5,1.5L8.47,12.63z"android:fillColor="#FFFFFF"/></group></vector>

2. 修改PhoneStatusBarPolicy.java

路径:frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java

方法:updateBluetooth()

修改前

privatefinalvoidupdateBluetooth(){inticonId=R.drawable.stat_sys_data_bluetooth_connected;StringcontentDescription=mResources.getString(R.string.accessibility_quick_settings_bluetooth_on);booleanbluetoothVisible=false;if(mBluetooth!=null){// Bug 2687381, The Bluetooth icon is not displayed normally.Log.d(TAG,"updateBluetooth(), mIsActive:"+mBluetooth.isBluetoothAudioActive());if(mBluetooth.isBluetoothConnected()&&(mBluetooth.isBluetoothAudioActive()||!mBluetooth.isBluetoothAudioProfileOnly())){contentDescription=mResources.getString(R.string.accessibility_bluetooth_connected);bluetoothVisible=mBluetooth.isBluetoothEnabled();}}// ...}

修改后

privatefinalvoidupdateBluetooth(){// Create by yeruilai 2026-6-6 19:54:14 Display Bluetooth icon when open// int iconId = R.drawable.stat_sys_data_bluetooth_connected;inticonId=R.drawable.stat_sys_data_bluetooth;StringcontentDescription=mResources.getString(R.string.accessibility_quick_settings_bluetooth_on);booleanbluetoothVisible=false;if(mBluetooth!=null){// Bug 2687381, The Bluetooth icon is not displayed normally.Log.d(TAG,"updateBluetooth(), mIsActive:"+mBluetooth.isBluetoothAudioActive());// Create by yeruilai 2026-6-6 19:54:14 Display Bluetooth icon when openbluetoothVisible=mBluetooth.isBluetoothEnabled();if(mBluetooth.isBluetoothConnected()&&(mBluetooth.isBluetoothAudioActive()||!mBluetooth.isBluetoothAudioProfileOnly())){contentDescription=mResources.getString(R.string.accessibility_bluetooth_connected);bluetoothVisible=mBluetooth.isBluetoothEnabled();// Create by yeruilai 2026-6-6 19:54:14 Display Bluetooth icon when openiconId=R.drawable.stat_sys_data_bluetooth_connected;}}// ...}

修改点

private final void updateBluetooth() { - int iconId = R.drawable.stat_sys_data_bluetooth_connected; + // Create by yeruilai 2026-6-6 19:54:14 Display Bluetooth icon when open + // int iconId = R.drawable.stat_sys_data_bluetooth_connected; + int iconId = R.drawable.stat_sys_data_bluetooth; String contentDescription = mResources.getString(R.string.accessibility_quick_settings_bluetooth_on); boolean bluetoothVisible = false; if (mBluetooth != null) { // Bug 2687381, The Bluetooth icon is not displayed normally. Log.d(TAG, "updateBluetooth(), mIsActive:" + mBluetooth.isBluetoothAudioActive()); + // Create by yeruilai 2026-6-6 19:54:14 Display Bluetooth icon when open + bluetoothVisible = mBluetooth.isBluetoothEnabled(); if (mBluetooth.isBluetoothConnected() && (mBluetooth.isBluetoothAudioActive() || !mBluetooth.isBluetoothAudioProfileOnly())) { contentDescription = mResources.getString( R.string.accessibility_bluetooth_connected); bluetoothVisible = mBluetooth.isBluetoothEnabled(); + // Create by yeruilai 2026-6-6 19:54:14 Display Bluetooth icon when open + iconId = R.drawable.stat_sys_data_bluetooth_connected; } }

附图

http://www.jsqmd.com/news/1233540/

相关文章:

  • Codex自动更新故障分析与防护方案
  • XUnity Auto Translator:为Unity游戏开启多语言世界的智能翻译引擎
  • 韩国Hip-Hop音乐产业生态与全球化策略解析
  • 重塑AI的“骨骼”:当精度扩散成为LLM权重的“超级压缩器”
  • 具身智能的TVA-VLA双引擎架构(系列)
  • Java面试备战全攻略:AI时代下如何高效准备与争取高薪
  • 本科生AI降重工具选择与使用指南
  • LED显示屏驱动技术解析与实践指南
  • 终极免费岛屿设计工具:5步打造你的梦想动物森友会岛屿
  • C# Task 进阶:WaitAll / WaitAny / WhenAll / WhenAny
  • 苹果AI战略转型:Gemini技术集成与Siri重构
  • AI培训项目风险管理与成本控制实践
  • Python高效开发:2020年十大实用库解析与应用
  • 3步完成GitHub汉化:终极GitHub中文插件安装指南
  • 具身智能的TVA-VLA双引擎架构(2)
  • Unity集成BepuPhysics2:突破物理性能瓶颈的架构设计与工程实践
  • 数据科学实习通关路径:JD反向拆解与鲁棒性工程实践
  • 2026精选:本土制造企业实力与创新产品深度解析 - 甄选服务推荐
  • AI时代Java程序员的核心竞争力:从CRUD到架构师的价值跃迁
  • 如何快速优化游戏性能:终极时间控制指南
  • 基于Spring Boot+Vue的毕业设计:员工绩效考核系统实战指南
  • 从“统一位宽是浪费”说起:一种自适应混合基数分解的LLM权重压缩构想
  • 最近试了下AI Offer,用AI来进化简历和模拟面试还挺简单的
  • 具身智能的TVA-VLA双引擎架构(3)
  • Python自动化报表生成教程
  • SCMP证书报考官网怎么找 - 众智商学院官方
  • 名校招生机制解析:公平性与多元化的平衡之道
  • LangChain与LangGraph框架选型指南:智能体开发实战解析
  • 徐州 24 小时上门回收黄金深度实测科普|2026 七月大盘行情,居家变现全套风险排查与正规门店服务标准 - 不晚生活号
  • AI代码生成与艺术风格融合:Codex转生成摇曳鳗一舞部署实践