Android R状态栏显示蓝牙图标

1,174

Anroid R上开启蓝牙后,状态栏上并不会直接显示蓝牙图标的。只有在蓝牙连接传输的时候才会有蓝牙图标显示。

原生实现是在PhoneStatusBarPolicy.java中:

    private final void updateBluetooth() {
        ......
        if (mBluetooth != null) {
            if (mBluetooth.isBluetoothConnected()
                    && (mBluetooth.isBluetoothAudioActive()
                    || !mBluetooth.isBluetoothAudioProfileOnly())) {
                contentDescription = mResources.getString(
                        R.string.accessibility_bluetooth_connected);
                bluetoothVisible = mBluetooth.isBluetoothEnabled();
            }
        }
        ......
    }

解决方案:

将bluetoothVisible赋值的条件设置为bluetooth enable。

         boolean bluetoothVisible = false;
         if (mBluetooth != null) {
+            if(mBluetooth.isBluetoothEnabled()){
+               bluetoothVisible = mBluetooth.isBluetoothEnabled();
+            }
             if (mBluetooth.isBluetoothConnected()
                     && (mBluetooth.isBluetoothAudioActive()
                     || !mBluetooth.isBluetoothAudioProfileOnly())) {
                 contentDescription = mResources.getString(
                         R.string.accessibility_bluetooth_connected);
-                bluetoothVisible = mBluetooth.isBluetoothEnabled();
+                //bluetoothVisible = mBluetooth.isBluetoothEnabled();
             }