导航:首页 > 软件资讯 > 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蓝牙怎么设置自动重连相关的资料

热点内容
做一个app或者网页用什么编程 浏览:766
一体机服务器运行失败怎么办 浏览:927
longjava比较大小 浏览:521
clojure编程pdf 浏览:11
一年级数学圈一圈的算法 浏览:100
完整的python 浏览:31
c51单片机数字钟 浏览:912
apk文件反编译后安装包损坏 浏览:807
app图标分别是什么 浏览:358
linux全选命令 浏览:365
怎么用华硕app 浏览:954
小明台湾通道加密 浏览:366
apriori算法的java 浏览:706
jscanvas压缩图片 浏览:382
单片机与汽车单片机有何不同 浏览:963
兽医云平台服务器 浏览:315
php循环字母 浏览:657
盛达是什么APP 浏览:217
android计算屏幕高度 浏览:671
自己做红包解压球 浏览:493