android 蓝牙sdk封装,Android 蓝牙SDK 使用文档.PDF

彭仲卿
2023-12-01

Android 蓝牙SDK 使用文档

Android 蓝牙SDK 使用文档

目录

1. 导入SDK 2

2. 基本配置 2

3. 初始化 2

3.1. 通过初始化获取到蓝牙的服务: 2

3.2. 注册Android 广播 2

4. 操作 5

4.1. 搜索 5

4.2. 停止搜索 5

4.3. 发送命令 5

4.4. 连接设备 6

4.5. 断开连接 6

4.6. 关闭蓝牙服务 6

附录一:3rdSDK id 列表 6

附录二 更新履历 7

1

1. 导入SDK

将下载包中的libs 文件夹合并到本地工程libs 子目录下;在Eclipse 中右键

工程根目录,选择Properties -> Java Build Path -> Libraries,然后点击Add

External JARs... 选择指向jar 的路径,点击OK,即导入成功。 (ADT17 及以上

不需要手动导入)

2. 基本配置

配置manifast :

配置 service (康诺云):

android:name= "com.chronocloud.ryfibluetoothlibrary.service.BluetoothServic

e" android:enabled= "true" />

3. 初始化

3.1. 通过初始化获取到蓝牙的服务:

try {

BluetoothService mBluetoothService = BluetoothFactory.getInstance()

.initBluetooth(mThirdSdkID,

getApplicationContext());

} catch (BluetoothException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

参数 释义

mThirdSdkID 第三方sdk的唯一标示,见附录一。

getApplicationContext() 全局上下文对象

3.2. 注册Android 广播

动态注册:

IntentFilter filter = new IntentFilter();

//设备上报

2

filter.addAction(BluetoothMessage.ACTION_ON_DEVICE_FOUND);

//报警上报

filter.addAction(BluetoothMessage.ACTION_ON_ALARM_REPORTED);

//属性上报

filter.addAction(BluetoothMessage.ACTION_ON_ATTR_CHANGED);

//连接状态上报

filter.addAction(BluetoothMessage.ACTION_ON_CONNECT_CHANGED);

//连接异常上报

filter.addAction

 类似资料: