蓝牙配对弹框默认允许关闭

 

蓝牙配对的时候,会有个以下的弹框,客户需求是不需要人为去点击,默认允许配对

 

实际处理弹框配对的是BluetoothPairingController.java

 

BluetoothPairingRequest.java这个文件主要负责处理配对弹框的广播申请,直接去掉那些流程,确认配对即可

--- a/src/com/android/settings/bluetooth/BluetoothPairingRequest.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingRequest.java
@@ -44,18 +44,20 @@ public final class BluetoothPairingRequest extends BroadcastReceiver {
         (PowerManager)context.getSystemService(Context.POWER_SERVICE);
     BluetoothDevice device =
         intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
-    String deviceAddress = device != null ? device.getAddress() : null;
-    String deviceName = device != null ? device.getName() : null;
-    boolean shouldShowDialog = LocalBluetoothPreferences.shouldShowDialogInForeground(
-        context, deviceAddress, deviceName);
-    if (powerManager.isInteractive() && shouldShowDialog) {
-      // Since the screen is on and the BT-related activity is in the foreground,
-      // just open the dialog
-      context.startActivityAsUser(pairingIntent, UserHandle.CURRENT);
-    } else {
-      // Put up a notification that leads to the dialog
-      intent.setClass(context, BluetoothPairingService.class);
-      context.startServiceAsUser(intent, UserHandle.CURRENT);
-    }
+
+    device.setPairingConfirmation(true);
+    // String deviceAddress = device != null ? device.getAddress() : null;
+    // String deviceName = device != null ? device.getName() : null;
+    // boolean shouldShowDialog = LocalBluetoothPreferences.shouldShowDialogInForeground(
+    //     context, deviceAddress, deviceName);
+    // if (powerManager.isInteractive() && shouldShowDialog) {
+    //   // Since the screen is on and the BT-related activity is in the foreground,
+    //   // just open the dialog
+    //   context.startActivityAsUser(pairingIntent, UserHandle.CURRENT);
+    // } else {
+    //   // Put up a notification that leads to the dialog
+    //   intent.setClass(context, BluetoothPairingService.class);
+    //   context.startServiceAsUser(intent, UserHandle.CURRENT);
+    // }
   }

 

参考:https://blog.csdn.net/qq_28391385/article/details/140715330

https://blog.csdn.net/qq_45698138/article/details/134879026

https://blog.csdn.net/wenzhi20102321/article/details/139705795

 

posted @ 2024-12-28 10:14  M-kobe  阅读(66)  评论(0)    收藏  举报