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

 

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

 

实际处理弹框配对的是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 @   M-kobe  阅读(21)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
点击右上角即可分享
微信分享提示