Android 蓝牙4.0 BLE 获取链接设备Rssi值
来源:互联网 发布:下载天际通软件 编辑:程序博客网 时间:2024/05/21 11:04
在网上查了很多资料,没有BLE获取RSSI值的资料,这几天弄了BLE 的Rssi值获取,写下来,做记录~
蓝牙BLE 服务回调方法
// 通过BLE API的不同类型的回调方法@SuppressLint("NewApi")private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {// 当连接状态发生改变@Overridepublic void onConnectionStateChange(BluetoothGatt gatt, int status,int newState) {String intentAction;// 当蓝牙设备已经连接if (newState == BluetoothProfile.STATE_CONNECTED) {intentAction = ACTION_GATT_CONNECTED;mConnectionState = STATE_CONNECTED;broadcastUpdate(intentAction);Log.i(TAG, "Connected to GATT server.已经链接上GATT服务");// Attempts to discover services after successful connection.// 试图发现服务连接成功后。Log.i(TAG, "Attempting to start service discovery试图发现服务连接成功后。:"+ mBluetoothGatt.discoverServices());// 当设备无法连接} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {intentAction = ACTION_GATT_DISCONNECTED;mConnectionState = STATE_DISCONNECTED;close();Log.i(TAG, "Disconnected from GATT server.不能链接上GATT服务");broadcastUpdate(intentAction);}}// 发现新服务端@Overridepublic void onServicesDiscovered(BluetoothGatt gatt, int status) {if (status == BluetoothGatt.GATT_SUCCESS) {broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED);} else {Log.w(TAG, "onServicesDiscovered received: " + status);}}// 读取特征值@Overridepublic void onCharacteristicRead(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic, int status) {// TODO Auto-generated method stubsuper.onCharacteristicRead(gatt, characteristic, status);Log.d(TAG, "读到数据了的");if (status == BluetoothGatt.GATT_SUCCESS) {broadcastReadUpdate(ACTION_DATA_AVAILABLE, characteristic);}}// 写出特征值@Overridepublic void onCharacteristicWrite(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic, int status) {// TODO Auto-generated method stubsuper.onCharacteristicWrite(gatt, characteristic, status);Log.d(TAG, "写出数据了~~");if (status == BluetoothGatt.GATT_SUCCESS) {broadcastWriteUpdate(ACTION_WRITE_DATA, characteristic);}}@Overridepublic void onCharacteristicChanged(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic) {broadcastReadUpdate(ACTION_DATA_AVAILABLE, characteristic);}@Overridepublic void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {// TODO Auto-generated method stubsuper.onReadRemoteRssi(gatt, rssi, status);//将回调的RSSI值赋值BLERSSI=rssi;}};
重点是最后一个回调方法onReadRemoteRssi(),
//是否能读取到已连接设备的RSSI值//执行该方法一次,获得蓝牙回调onReadRemoteRssi()一次 /** * Read the RSSI for a connected remote device. * */ public boolean getRssiVal() { if (mBluetoothGatt == null) return false; return mBluetoothGatt.readRemoteRssi(); }
调用getRssiVal(),回调方法返回一次RSSi值。。。。。。
Demo http://download.csdn.net/detail/bruce60/8850593
阅读全文
0 0
- Android 蓝牙4.0 BLE 获取链接设备Rssi值
- android ble 蓝牙4.0开发-rssi
- android BLE蓝牙RSSI数据的读写
- <蓝牙BLE>cc2540主机读RSSI值
- Android蓝牙BLE之RSSI数据的读写(1)
- Android蓝牙BLE之RSSI读写(2)
- Android蓝牙BLE之RSSI读写(2)
- Android蓝牙BLE之RSSI数据的读写(1)
- android 蓝牙ble设备开发
- Android蓝牙4.0BLE
- Android ble 蓝牙4.0
- Android BLE蓝牙4.0
- 关于Android蓝牙4.0Ble设备开发技术点
- Android 蓝牙强度Rssi
- Android智能设备蓝牙连接(BLE)
- Android BLE设备蓝牙通信框架BluetoothKit
- Android 蓝牙4.0 Bluetooth BLE 写数据(修改BLE设备的属性)
- Android 蓝牙4.0 Ble 连接Ble模块
- 关于经典蓝牙和低功耗蓝牙的区别
- fork和vfork函数
- vue 相关技术文章地址和知识点整理
- 全备份、增量备份与差量备份
- [P1197][JSOI2008]星球大战
- Android 蓝牙4.0 BLE 获取链接设备Rssi值
- 使用phpize遇到问题
- Spring(17)——对JSR330标准的支持
- 全局dialog
- 每日一题(33)——用两个栈实现一个队列的功能?要求给出算法和思路
- Java中Long、String、Date 类型之间的转换
- CAD 偏移和复制、移动的区别
- Linux远程登录火狐浏览器无法打开的问题
- 序列化和反序列化初探