蓝牙模块
蓝牙初始化
在使用蓝牙前调用(已调用过XYMobileSdk.getInstance().init(getContext())则不需要再调用)
XYMobileSdk.getBleSdk().init(Context context);
添加蓝牙结果回调
XYMobileSdk.getBleSdk().addBleCallback(BleCallback bleCallback);
BleCallback
interface BleCallback {
onLeScan(List<BleDevice> bleDeviceList);
onConnectState(BleDevice bleDevice, boolean isConnect);
}
删除蓝牙结果回调
XYMobileSdk.getBleSdk().removeBleCallback(BleCallback bleCallback);
判断蓝牙是否打开
boolean isBleEnable = XYMobileSdk.getBleSdk().isBleEnabled();
打开蓝牙,弹框看用户是否允许
XYMobileSdk.getBleSdk().enableBle(Context context);
开始扫描蓝牙设备
blePrefixFilter为过滤蓝牙的前缀,搜索到的蓝牙设备会在蓝牙结果回调中展示
XYMobileSdk.getBleSdk().startLeScan(String[] blePrefixFilter);
停止扫描蓝牙设备
XYMobileSdk.getBleSdk().stopLeScan();
连接选中的蓝牙
此pickedDevice在蓝牙结果回调中选择
XYMobileSdk.getBleSdk().connect(BleDevice pickedDevice);
使用蓝牙传输配网数据,进行配网
ssid: wifi 名称 password:wifi 密码 deviceCode:设备登录用的 deviceCode isHidden:是否为隐藏wifi
XYMobileSdk.getBleSdk().sendBleData(String ssid, String password, String deviceCode, boolean isHidden);
释放蓝牙连接
XYMobileSdk.getBleSdk().releaseBle();