首页 > 其他分享 >[BT][Setting]如何在Framework层实现BT的自动配对

[BT][Setting]如何在Framework层实现BT的自动配对

时间:2023-09-13 18:13:24浏览次数:26  
标签:case BluetoothDevice PAIRING VARIANT BT Framework Setting mDevice 配对

https://blog.csdn.net/weixin_44343246/article/details/109768335

[DESCRIPTION]

 客户有需求在没有屏和TP的情况下,如果有其他蓝牙对此设备进行配对,希望能自动完成配对动作,而不需要弹出需要用户确认的对话框。
  • 1

Android手机平台上当对方发起配对时主要使用种配对方式:

1.SSP数字比对,即双方手机产生配对密钥,由用户选择yes or no来进行鉴权连接。
2.Pin Code, 如果对方蓝牙不支持BT2.1以上版本,一般会走此流程,即双方输入四位数字进行配对。此方式需要预置4为数字,当对方发起配对时,需要输入此四位数字。
  • 1
  • 2

下面的内容是如何添加代码来实现BT自动配对的流程!

修改文件: (alps\packages\apps\settings\src\com\android\settings\bluetooth\BluetoothPairingRequest.java)
总共修改5处。

1.import android.util.Log;

2.在BluetoothPairingRequest类中定义两个变量
private static int mType = 0;
private BluetoothDevice mDevice;

3.在BluetoothPairingRequest 类中添加私有方法
private void autoPair(int value) {
switch (mType) {
case BluetoothDevice.PAIRING_VARIANT_PIN:
byte[] pin= {0,1,2,3};
mDevice.setPin(pin);
break;
case BluetoothDevice.PAIRING_VARIANT_PASSKEY:
mDevice.setPasskey(value);
break;
case BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION:
case BluetoothDevice.PAIRING_VARIANT_CONSENT:
mDevice.setPairingConfirmation(true);
break;
case BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY:
case BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN:
// Do nothing.
break;
case BluetoothDevice.PAIRING_VARIANT_OOB_CONSENT:
mDevice.setRemoteOutOfBandData();
break;
default:
Log.e(“autoPair”, “Incorrect pairing type received”);
}
}
4. 在 int type = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT,
BluetoothDevice.ERROR);
后面添加以下两句
mType = type;
mDevice = device;
5. 注释掉context.startActivity(pairingIntent);这句,
并在 if (powerManager.isScreenOn() &&前面添加
int pairingKey = intent.getIntExtra (BluetoothDevice.EXTRA_PAIRING_KEY,
BluetoothDevice.ERROR);
autoPair(pairingKey);

标签:case,BluetoothDevice,PAIRING,VARIANT,BT,Framework,Setting,mDevice,配对
From: https://www.cnblogs.com/bluestorm/p/17700368.html

相关文章

  • Bug库____org.springframework.jdbc.IncorrectResultSetColumnCountException: Incorr
    Bug:使用到了spring的jdbctemplate模板使用到以下template.queryForObject(sql,requiredType)template.queryForList(sql,elementType,args)报以下错误org.springframework.jdbc.IncorrectResultSetColumnCountException:Incorrectcolumncount:expected1,actual3检查完......
  • BUG(Spring Framework JdbcTemplate) org.springframework.jdbc.IncorrectResultSetCo
    一.SpringFramework queryForObject问题1.spring4.0之前使用使用jdbctemplate的queryForObject(Stringsql,Object[]args,RowMapper<T>rowMapper)直接放入class类型会报错org.springframework.jdbc.IncorrectResultSetColumnCountException:Incorrectcolumncount:expec......
  • .Net Framework使用Autofac实现依赖注入
    .NetFramework使用Autofac实现依赖注入前言最近也是找了快2周的工作了,收到的面试邀请也就几个,然后有个面试题目是用asp.netmvc+Entityframework做一个学生信息增删改查系统。因为题目要求了用Entityframework也就是EF那也就不上core了,web项目也是用Framework4.8去做的。......
  • IDEA2023.2以上版本没有“添加框架支持”(Add Framework Support)选项解决办法
    问题:IDEA升级2023.2以上版本后,想创建JavaWeb项目,无法在“新建项目”后,通过鼠标右键“添加框架支持”(AddFrameworkSupport)的方式添加Web支持。 解决办法:选中模块,双击shift(或“帮助”菜单-->查找),选择操作,中文版搜索“添加框架支持”,英文版搜索“AddFrameworkSupport”,即可......
  • .NET Framework 4.7.2下 Hangfire 的集成(转载)
    原文地址:.NETFramework4.7.2下Hangfire的集成-SamXiao-博客园(cnblogs.com).NETFramework4.7.2下Hangfire的集成  参考资料:开源的.NET定时任务组件Hangfire解析:https://www.cnblogs.com/pengze0902/p/6583119.html.NetCore简单的Hangfire部署Demo:https://......
  • 搭上Framework这艘快艇,你能把好舵吗?
    随着Android式微,学习Framework就已然成为Android程序员的风向标。Android式微,Framework为何成为香饽饽?岗位多,薪资高具有转行优势Android开发如果想转行,还是在Android的基础之上进行转比较好,比如:Android系统开发、车载开发、音视频开发、智能家居、Flutter……等,要么就继续走下去......
  • 【9月摸鱼计划】IGBT在光伏上的应用
    IGBT(绝缘栅双极晶体管)在光伏领域中具有广泛的应用。IGBT作为一种高效的电力电子器件,能够在复杂的电力转换和控制系统中有出色的表现。在光伏系统中,IGBT主要应用于逆变器、直流变换器和交流电源等方面。逆变器是光伏系统中的关键部分,它负责将直流电转换为交流电以便于电网使用。在......
  • 接口文档,jwt介绍和构成,jwt签发与认证,base64编码,drf-jwt使用,django-rest-framewor
    1接口文档#作为后端,接口写好了#作为前端,需要使用我们写的接口(移动端,web,桌面端)#后端需要写接口文档#接口文档的展现形式: 1word,md,写好传到公司的某个平台---》前端可以下载2自动生成接口文档---》后端通过配置--》把所写的接口都自动生成---》地址--》访问......
  • 报错解决 :Resolved [org.springframework.web.bind.MissingServletRequestParameterE
    报错解决:Resolved[org.springframework.web.bind.MissingServletRequestParameterException解决方法:RequestParam注解加上required=false属性。这样请求参数可以传null对象。如果没有加上required=false属性,这样请求参数传""空字符串也不会报错。如果没有加上required=......
  • 微服务启动失败,报错信息:java.lang.RuntimeException: dynamic-datasource Please chec
    【问题描述】Causedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'dataSource'definedinclasspathresource[com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAutoConfiguration.cl......