Android 12.0 开启蓝牙状态栏即显示蓝牙图标

2 阅读1分钟

12.0 开启蓝牙状态栏即显示蓝牙图标

最近收到客户反馈想要在开启蓝牙时状态栏就能显示出蓝牙图标,我们系统默认是连上设备后状态栏才显示出蓝牙图标,具体修改参照如下:

packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java

    private final void updateBluetooth() {
        int iconId = R.drawable.stat_sys_data_bluetooth_connected;
        String contentDescription =
                mResources.getString(R.string.accessibility_quick_settings_bluetooth_on);
        boolean bluetoothVisible = false;
        if (mBluetooth != null) {
+            if(mBluetooth.isBluetoothEnabled()) {
+                contentDescription = mResources.getString(R.string.accessibility_quick_settings_bluetooth_on);
+                bluetoothVisible = mBluetooth.isBluetoothEnabled();
+                iconId = R.drawable.ic_qs_bluetooth_on;
+            }
            if (mBluetooth.isBluetoothConnected()
                    && (mBluetooth.isBluetoothAudioActive()
                    || !mBluetooth.isBluetoothAudioProfileOnly())) {
+                iconId = R.drawable.stat_sys_data_bluetooth_connected;
                contentDescription = mResources.getString(
                        R.string.accessibility_bluetooth_connected);
                bluetoothVisible = mBluetooth.isBluetoothEnabled();
            }
        }

重新编译验证,修改生效,开启蓝牙时状态栏即显示蓝牙图标