导航:首页 > 软件资讯 > APP蓝牙怎么设置自动重连

APP蓝牙怎么设置自动重连

发布时间:2023-12-20 19:54:22

A. 如何实现android蓝牙自动配对连接

android蓝牙自动配对连接的具体代码如下:
1. 获取蓝牙适配器BluetoothAdapter blueadapter=BluetoothAdapter.getDefaultAdapter();
如果BluetoothAdapter 为null,说明android手机没有蓝牙模块。
2. 判断蓝牙模块是否开启,blueadapter.isEnabled() true表示已经开启,false表示蓝牙并没启用。
3. 启动配置蓝牙可见模式,即进入可配对模式Intent in=new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
in.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 200);
startActivity(in); ,200就表示200秒。
4. 获取蓝牙适配器中已经配对的设备Set device=blueadapter.getBondedDevices();
当然,还需要在androidManifest.xml中声明蓝牙的权限5.自动配对设置Pin值

static public boolean autoBond(Class btClass, BluetoothDevice device, String strPin)
throws Exception {
Method autoBondMethod = btClass.getMethod("setPin", new Class[] { byte[].class });
Boolean result = (Boolean) autoBondMethod
.invoke(device, new Object[] { strPin.getBytes() });
return result;
}

6.开始配对请求
static public boolean createBond(Class btClass, BluetoothDevice device) throws Exception {
Method createBondMethod = btClass.getMethod("createBond");
Boolean returnValue = (Boolean) createBondMethod.invoke(device);
return returnValue.booleanValue();
}

阅读全文

与APP蓝牙怎么设置自动重连相关的资料

热点内容
如何运用mex函数编译c 浏览:896
24岁程序员倒在工作上 浏览:919
怎么算梁的加密区 浏览:93
2016版office怎么解压 浏览:270
怎么把安卓手机调的更暗 浏览:167
苹果空间新算法 浏览:91
android文字动画效果 浏览:146
java调试命令 浏览:213
android子线程looper 浏览:782
linux安装java7 浏览:189
单片机fdh 浏览:107
单片机原理与应用下载 浏览:590
顺风车车主app在哪里下载 浏览:235
雷石柏云服务器功率 浏览:102
全球服是什么服务器 浏览:237
传感器怎么连接服务器 浏览:705
大数学pdf 浏览:646
哪个app可以登记自己的藏书 浏览:89
怎么用车贷款哪个app好 浏览:7
加密后打开只有300m 浏览:308