Android 低功耗蓝牙开发(数据交互)

  • 前言
  • 正文
    • 一、BluetoothGattCallback
      • 1. onPhyUpdate
      • 2. onPhyRead
      • 3. onServicesDiscovered
      • 4. onCharacteristicRead
      • 5. onCharacteristicWrite
      • 6. onCharacteristicChanged
      • 7. onDescriptorRead
      • 8. onDescriptorWrite
      • 9. onReliableWriteCompleted
      • 10. onReadRemoteRssi
      • 11. onMtuChanged
    • 二、使用
      • 1. 连接设备
      • 2. 获取MTU Size
      • 3. 发现服务
      • 4. 打开通知
      • 5. 写入数据
      • 6. 收到数据
      • 7. Phy值读取和改变
      • 8. 读取特性、描述符、RSSI
    • 三、源码

前言

  在上一篇低功耗蓝牙开发文章中,我讲述了扫描和连接,本篇文章讲述数据的交互。当了解了数据交互后就可以开始进行低功耗蓝牙硬件和手机App软件相结合的项目,例如蓝牙音箱、蓝牙灯、蓝牙锁等等。

正文

  因为本篇文章会接着上一篇文章进行一个续写,上一篇文章 Android 低功耗蓝牙开发(扫描、连接),没看过的可以先看看,这样可以平稳过度,当然如果对扫描和连接都没有问题的可以直接从本篇文章开始看。

一、BluetoothGattCallback

  在进行编码之前首先要了解一个很重要的东西,那就是BluetoothGattCallback,这个类非常重要,可以说你能不能进行低功耗蓝牙的数据交互全看它了。

之前在进行低功耗蓝牙连接的时候使用的是Gatt连接,不知道你是否还记得。回顾一下:

可以看到通过连接gatt,使用了抽象类BluetoothGattCallback,重写了里面的一个onConnectionStateChange方法,进行设备连接状态的回调。这个类里面还有一些方法,可以用于针对开发中的使用进行调用。下面来介绍一下:

方法 描述
onPhyUpdate 物理层改变回调
onPhyRead 设备物理层读取回调
onConnectionStateChange Gatt连接状态回调
onServicesDiscovered 发现服务回调
onCharacteristicRead 特性读取回调
onCharacteristicWrite 特性写入回调
onCharacteristicChanged 特性改变回调
onDescriptorRead 描述读取回调
onDescriptorWrite 描述写入回调
onReliableWriteCompleted 可靠写入完成回调
onReadRemoteRssi 读取远程设备信号值回调
onMtuChanged MtuSize改变回调
onConnectionUpdated 连接更新回调

这里光有一个表好像是没有啥用,在介绍详细的API方法及里面的属性值之前先做好准备工作。

BluetoothGattCallback是一个抽象类,那么自然需要一个实现类,在之前的文章中我是通过匿名实现里面的onConnectionStateChange方法对低功耗蓝牙设备进行连接和断开的监听的。

不过在实际开发中这样的做法并不可取,因为一个蓝牙项目里面不可能只有一个地方需要使用这个监听,那么此时就需要封装一个类去单独实现BluetoothGattCallback中的方法,然后再根据需要取使用。

下面在com.llw.bledemo下新建一个callback包,包里面新建一个BleCallback类,然后继承BluetoothGattCallback,重写里面的onConnectionStateChange方法,代码如下:

public class BleCallback extends BluetoothGattCallback {private static final String TAG = BleCallback.class.getSimpleName();/*** 连接状态改变回调** @param gatt     gatt* @param status   gatt连接状态* @param newState 新状态*/@Overridepublic void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {if (status == BluetoothGatt.GATT_SUCCESS) {switch (newState) {case BluetoothProfile.STATE_CONNECTED://连接成功Log.d(TAG, "连接成功");break;case BluetoothProfile.STATE_DISCONNECTED://断开连接Log.e(TAG, "断开连接");break;default:break;}} else {Log.e(TAG, "onConnectionStateChange: " + status);}}
}

为了区别于上一篇文章,我这里会新建一个DataExchangeActivity来做数据的交互,不会影响到上一篇文章的内容。然后在MainActivity,点击列表item时调用的connectDevice方法中跳转到DataExchangeActivity中,通过传递蓝牙对象过去。

接下来看看DataExchangeActivity中做了什么?

public class DataExchangeActivity extends AppCompatActivity {private static final String TAG = DataExchangeActivity.class.getSimpleName();/*** Gatt*/private BluetoothGatt bluetoothGatt;/*** 设备是否连接*/private boolean isConnected = false;/*** Gatt回调*/private BleCallback bleCallback;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_data_exchange);//初始化bleCallback = new BleCallback();//获取上个页面传递过来的设备BluetoothDevice device = getIntent().getParcelableExtra("device");//连接gatt 设置Gatt回调bluetoothGatt = device.connectGatt(this, false, bleCallback);}/*** 断开设备连接*/private void disconnectDevice() {if (isConnected && bluetoothGatt != null) {bluetoothGatt.disconnect();}}/*** Toast提示** @param msg 内容*/private void showMsg(String msg) {Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();}
}

很简单这个代码,就是接收上个页面传递过来的蓝牙对象,然后进行gatt连接。直接传入实例化之后的bleCallback即可,请注意关于gatt的处理都是在子线程中进行的,可以验证一下:

运行一下,进入交互页面。

下面进行GattCallback中的API介绍。

1. onPhyUpdate

 /*** 物理层改变回调** @param gatt   gatt* @param txPhy  发送速率  1M 2M* @param rxPhy  接收速率  1M 2M* @param status 更新操作的状态*/@Overridepublic void onPhyUpdate(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {super.onPhyUpdate(gatt, txPhy, rxPhy, status);}

通过gatt.setPreferredPhy()方法触发,例如:

 //设置 2M gatt.setPreferredPhy(BluetoothDevice.PHY_LE_2M, BluetoothDevice.PHY_LE_2M, BluetoothDevice.PHY_OPTION_NO_PREFERRED);

2. onPhyRead

 /*** 读取物理层回调** @param gatt   gatt* @param txPhy  发送速率  1M 2M* @param rxPhy  接收速率  1M 2M* @param status 更新操作的状态*/@Overridepublic void onPhyRead(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {super.onPhyRead(gatt, txPhy, rxPhy, status);}

通过gatt.readPhy();进行触发,该方法不需要传入参数。

3. onServicesDiscovered

 /*** 发现服务回调** @param gatt   gatt* @param status gatt状态*/@Overridepublic void onServicesDiscovered(BluetoothGatt gatt, int status) {super.onServicesDiscovered(gatt, status);}

通过gatt.discoverServices(); 触发,没有输入参数。

4. onCharacteristicRead

 /*** 特性读取回调** @param gatt           gatt* @param characteristic 特性* @param status         gatt状态*/@Overridepublic void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {super.onCharacteristicRead(gatt, characteristic, status);}

通过gatt.readCharacteristic(characteristic);触发,需要构建一个BluetoothGattCharacteristic 对象,在后面的实例中会演示。

5. onCharacteristicWrite

 /*** 特性写入回调** @param gatt           gatt* @param characteristic 特性* @param status         gatt状态*/@Overridepublic void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {super.onCharacteristicWrite(gatt, characteristic, status);}

通过gatt.writeCharacteristic(characteristic);触发,需要BluetoothGattCharacteristic 对象,在后面的实例中会演示。

6. onCharacteristicChanged

 /*** 特性改变回调** @param gatt           gatt* @param characteristic 特性*/@Overridepublic void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {super.onCharacteristicChanged(gatt, characteristic);}

此回调的触发需要远程设备特性改变,通俗的说就是,你需要给设备发送消息之后,才会触发这个回调。在后面的实例中会演示。

7. onDescriptorRead

 /*** 描述符获取回调** @param gatt       gatt* @param descriptor 描述符* @param status     gatt状态*/@Overridepublic void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {super.onDescriptorRead(gatt, descriptor, status);}

通过gatt.readDescriptor(descriptor);触发,需要传入BluetoothGattDescriptor对象,在后面的实例中会演示。

8. onDescriptorWrite

 /*** 描述符写入回调** @param gatt       gatt* @param descriptor 描述符* @param status     gatt状态*/@Overridepublic void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {super.onDescriptorWrite(gatt, descriptor, status);}

通过gatt.writeDescriptor(descriptor);触发,需要传入BluetoothGattDescriptor 对象,在后面的实例中会演示。

9. onReliableWriteCompleted

 /*** 可靠写入完成回调** @param gatt   gatt* @param status gatt状态*/@Overridepublic void onReliableWriteCompleted(BluetoothGatt gatt, int status) {super.onReliableWriteCompleted(gatt, status);}

通过gatt.executeReliableWrite();触发,不需要参数,在实际中用的不是很多。

10. onReadRemoteRssi

 /*** 读取远程设备的信号强度回调** @param gatt   gatt* @param rssi   信号强度* @param status gatt状态*/@Overridepublic void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {super.onReadRemoteRssi(gatt, rssi, status);}

通过gatt.readRemoteRssi();触发,无需参数,实际中使用不多。

11. onMtuChanged

 /*** Mtu改变回调** @param gatt   gatt* @param mtu    new MTU size* @param status gatt状态*/@Overridepublic void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {super.onMtuChanged(gatt, mtu, status);}

通过gatt.requestMtu(512);触发,需要传入请求的Mtu大小,最大是512,这里单位是字节,512是理论最大值,如果不设置就是默认23字节,而且传输本身用掉3字节,实际上携带数据只有20字节。在后面的实例中会演示。

最后的一个onConnectionUpdated回调无法进行覆写,就不介绍了,下面进入使用API环节。

二、使用

1. 连接设备

  第一步是连接,代码在上面已经写好,连接上设备之后,

2. 获取MTU Size

下一步就是获取MtuSize。

然后会触发onMtuChanged回调,

3. 发现服务

在onMtuChanged回调中去发现服务。

然后就会触发onServicesDiscovered回调,在这个回调中要做的就是打开通知开关。这个在之前没有提到,因为它不在基础的回调API中,但是打开通知开关属于描述符的内容,因此当你设置了之后会触发onDescriptorWriteh回调,还是先来看这个通知怎么打开吧。

4. 打开通知

  为了规范一些,将使用到的方法封装起来,这样便于管理,增加一个BleHelper类和BleConstant类。
新建一个utils包,包下建两个类,下面先看这个BleConstant类

public class BleConstant {/*** 服务 UUID */public static final String SERVICE_UUID = "0000ff01-0000-1000-8000-00805f9b34fb";/*** 特性写入 UUID */public static final String CHARACTERISTIC_WRITE_UUID = "0000ff02-0000-1000-8000-00805f9b34fb";/*** 特性读取 UUID */public static final String CHARACTERISTIC_READ_UUID = "0000ff10-0000-1000-8000-00805f9b34fb";/*** 描述 UUID */public static final String DESCRIPTOR_UUID = "00002902-0000-1000-8000-00805f9b34fb";/*** 电池服务 UUID*/public static final String BATTERY_SERVICE_UUID = "0000180f-0000-1000-8000-00805f9b34fb";/*** 电池特征(特性)读取 UUID*/public static final String BATTERY_CHARACTERISTIC_READ_UUID = "00002a19-0000-1000-8000-00805f9b34fb";/*** OTA服务 UUID */public static final String OTA_SERVICE_UUID = "5833ff01-9b8b-5191-6142-22a4536ef123";/*** OTA特征(特性)写入 UUID*/public static final String OTA_CHARACTERISTIC_WRITE_UUID = "5833ff02-9b8b-5191-6142-22a4536ef123";/*** OTA特征(特性)表示 UUID */public static final String OTA_CHARACTERISTIC_INDICATE_UUID = "5833ff03-9b8b-5191-6142-22a4536ef123";/*** OTA数据特征(特性)写入 UUID */public static final String OTA_DATA_CHARACTERISTIC_WRITE_UUID = "5833ff04-9b8b-5191-6142-22a4536ef123";
}

这里面都是常规的UUID常量值,就是一些服务和特性的标识符,这个UUID常量值由SIG联盟所规定的,当然也可以根据自己的硬件去做设置,值不是固定的,请根据实际的硬件为主。

下面是BleHelper类,代码如下:

public class BleHelper {/*** 启用指令通知*/public static boolean enableIndicateNotification(BluetoothGatt gatt) {//获取Gatt 服务BluetoothGattService service = gatt.getService(UUID.fromString(BleConstant.OTA_SERVICE_UUID));if (service == null) {return false;}//获取Gatt 特征(特性)BluetoothGattCharacteristic gattCharacteristic = service.getCharacteristic(UUID.fromString(BleConstant.OTA_CHARACTERISTIC_INDICATE_UUID));return setCharacteristicNotification(gatt, gattCharacteristic);}/*** 设置特征通知* return true, if the write operation was initiated successfully*/private static boolean setCharacteristicNotification(BluetoothGatt gatt, BluetoothGattCharacteristic gattCharacteristic) {//如果特性具备Notification功能,返回true就代表设备设置成功boolean isEnableNotification = gatt.setCharacteristicNotification(gattCharacteristic, true);if (isEnableNotification) {//构建BluetoothGattDescriptor对象BluetoothGattDescriptor gattDescriptor = gattCharacteristic.getDescriptor(UUID.fromString(BleConstant.DESCRIPTOR_UUID));gattDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);//写入描述符return gatt.writeDescriptor(gattDescriptor);} else {return false;}}
}

代码没有什么难度,下面就是在发现服务的回调中调用BleHelper中的方法。

当开启通知失败时断开gatt连接。

下面会进入onDescriptorWrite回调

当通知开启成功可以就可以进行数据的交互了,不过在此之前先运行一下,看程序是否按照我们所想的运行,看一下日志:

Very Good!

现在基本的前置工作都准备好了,下一步就是数据的读写了,首先来看看写数据到设备。

5. 写入数据

  常规来说写入数据的话肯定是要对设备做点什么,列如一个蓝牙灯,控制这个灯开关,那么这就是一条指令,指令的内容是App与设备端协商好的,这个要以实际的需求为主。假设我对一个蓝牙手环要进行数据的写入,那么肯定会有很多的指令,所以可以封装一个方法集中处理,依然写在BleHelper中。方法如下:

 /*** 发送指令* @param gatt gatt* @param command 指令* @param isResponse 是否响应* @return*/public static boolean sendCommand(BluetoothGatt gatt, String command, boolean isResponse) {//获取服务BluetoothGattService service = gatt.getService(UUID.fromString(BleConstant.OTA_SERVICE_UUID));if (service == null) {Log.e("TAG", "sendCommand: 服务未找到");return false;}//获取特性BluetoothGattCharacteristic characteristic = service.getCharacteristic(UUID.fromString(BleConstant.OTA_CHARACTERISTIC_WRITE_UUID));if (characteristic == null) {Log.e("TAG", "sendCommand: 特性未找到");return false;}//写入类型  WRITE_TYPE_DEFAULT  默认有响应, WRITE_TYPE_NO_RESPONSE  无响应。characteristic.setWriteType(isResponse ?BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT : BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);//将字符串command转Byte后进行写入characteristic.setValue(ByteUtils.hexStringToBytes(command));boolean result = gatt.writeCharacteristic(characteristic);Log.d("TAG", result ? "写入初始化成功:" + command : "写入初始化失败:" + command);return result;}

  下面解释一下这个方法的内容,首先通过服务UUID获取到Gatt服务,然后通过写数据特性UUID从服务中获取写数据特性,这里的UUID的值请根据自己的实际情况填写,不知道就问硬件工程师。然后根据传入的isResponse去设置是否需要响应,这里要弄清楚有响应和无响应的区别,有响应的速度比无响应慢,但是有响应更安全,因为你可以对每一次发出的数据进行一个确认,是否发送到,有无丢失。不过这样的话效率会比较低,一般来说实际开发中大部分指令型消息都会选择无响应,数据型消息会选择有响应。

这里增加一个工具类,代码如下:

public class ByteUtils {/*** Convert hex string to byte[]** @param hexString the hex string* @return byte[]*/public static byte[] hexStringToBytes(String hexString) {if (hexString == null || hexString.equals("")) {return null;}hexString = hexString.toUpperCase();int length = hexString.length() / 2;char[] hexChars = hexString.toCharArray();byte[] d = new byte[length];for (int i = 0; i < length; i++) {int pos = i * 2;d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));}return d;}public static String bytesToHexString(byte[] src) {StringBuilder stringBuilder = new StringBuilder("");if (src == null || src.length <= 0) {return null;}for (int i = 0; i < src.length; i++) {int v = src[i] & 0xFF;String hv = Integer.toHexString(v);if (hv.length() < 2) {stringBuilder.append(0);}stringBuilder.append(hv);}return stringBuilder.toString();}/*** Convert char to byte** @param c char* @return byte*/private static byte charToByte(char c) {return (byte) "0123456789ABCDEF".indexOf(c);}
}

然后就是对消息的内容转Byte,这里的指令长度有一个最大值就是之前通过onMtuChange回调时得到的数值,247 去掉3字节传输实际上就是244字节,那么你一次传输的最大字节就是244,这个值你不能写死,因为你要根据Android版本和蓝牙设备硬件去适配。最终通过setValue将值放入特性,然后通过写入特性传递给设备。然后返回一个boolean值,这个值只是表明写入特性的初始化成功,不代表就真的写入到设备中了,那么写入到设备成功的标识是什么呢?

先不急,我们先调用这个方法,
修改页面的布局文件activity_data_exchange.xml,代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="bottom"android:orientation="vertical"android:paddingBottom="@dimen/dp_20"tools:context=".DataExchangeActivity"><EditTextandroid:id="@+id/et_command"android:hint="请输入指令"android:layout_width="match_parent"android:layout_height="60dp"/><Buttonandroid:id="@+id/btn_send_command"android:layout_marginTop="10dp"android:text="发送指令"android:insetTop="0dp"android:insetBottom="0dp"android:layout_width="match_parent"android:layout_height="50dp"/></LinearLayout>

然后回到DataExchangeActivity,
先声明变量

private EditText etCommand;

然后在onCreate中

然后先写入一条指令给设备。例如0102,这对于我这个设备来说是一个切换模式的指令,这条指令不需要响应,那么在哪里确认这个指令写入到了设备呢?通过onCharacteristicWrite。
先修改一下这个回调方法中的内容。在BleCallback中,

下面运行一下:

下面来看看控制栏的日志打印:

写入成功。下面来看收到数据的处理

6. 收到数据

  如果你需要收到数据,那么就需要使用有响应的设置,这里设置为true。

当设备的特性改变时

我这里打印一下,然后运行。

01020,是我的蓝牙设备中定义一个值,收到0081 则表示正常,然后看控制台。

这里当我们进行有响应的数据写入时,设备收到后会先触发onCharacteristicChanged然后再触发onCharacteristicWrite。也就是先发送指令,设备收到回复后,再是你的指令写入成功,注意这个执行的顺序,这很重要,在实际开发中请注意这一点,然后再去写相应的业务逻辑。

还有一些其他的API也需要介绍一下怎么使用的,例如onPhyRead和onPhyUpdate。

7. Phy值读取和改变

  首先来看这个值的读取,比如我们在通知开启成功之后去读取这个设备的Phy

这个读取的方法要求你的Android版本必须要在8.0和8.0以上,因此如果你的Android设备是低版本的就不用考虑去使用这个API了,因为系统不支持。我是Android10.0所以没问题,调用这个方法API就会触发onPhyRead回调。我们在回调的时候打印一下内容,看看当前的硬件Phy是什么值。

运行一下看控制台打印了什么

都是1 就代表1M的发送和接收速率,那么你也可以改成2M,可以这么做,当我读取到速率为1M时就请求2M的速率。

然后就会触发onPhyUpdate回调,我们打印一下:


运行之后查看控制台:

Beautiful!现在我们知道这个Phy怎么改的了,那么在什么时候改呢?当你要传大数据的时候。例如你要对蓝牙设备中的软件进行升级,那么升级文件是比较大的,此时在条件允许提高传输速率可以降低等待时间。

8. 读取特性、描述符、RSSI

  一般来说这三个回调用的比较少,如果你不熟悉的话,前期可以使用。它们在不同的时候使用,由于获取特性和描述符需要一个参数,因此你需要在有这个参数的时候去调用它,比如当写入特性回调被触发时,

再比如特性改变时。

然后会触发onCharacteristicRead回调,在这个回调中打印一下特性的uuid。

其实说起来这个方法比较的鸡肋,这可能也是为什么使用的比较少的原因了,因为当我能知道特性是什么的时候,我直接就能拿到特性对象所携带的信息,根本不需要再去通过gatt.readCharacteristic(characteristic);去查看特性。说是这么说,不过该介绍的还是要有的,知道就可以了。

另一个描述符的读取也是一样的道理,可以在描述符写入回调时调用,

同时我还调用了gatt.readRemoteRssi,因为获取RSSI不需要参数,只要你的设备保持了连接,那么可以在任何时候获取RSSI,然后我们在对应的地方去打印一下:


下面运行一下:

这里可以看到我写入了0102之后设备的地址会发生改变,所以我退出了当前页面,再连接设备之后,发送了010200,这里我们看到了RSSI和描述符的UUID,不过特性的UUID并没有打印出来,这是为什么呢?

gatt.readCharacteristic(characteristic);执行后会返回一个boolean结果,打印一下这个结果看看。

运行打印一下:

那么来看看为什么会是false。

这里我突然想到一种可能性,是不是读取这个特性的对象有问题,我现在的这个特性的uuid是之前写特性的uuid,所以拿不到读特性的回调。然后试了一下,发现还是false,拿不到特性,这个就和硬件有关系了,蓝牙硬件会根据功能的需求,对特性进行改动,有一些特性不重要的就去掉了,因此针对我这个蓝牙设备来说就拿不到读特性。

三、源码

GitHub: BleDemo

山高水长,后会有期~

Android 低功耗蓝牙开发(数据交互)相关推荐

  1. Android 低功耗蓝牙开发简述

    低功耗蓝牙简述 一.什么是低功耗蓝牙? 二.怎么做低功耗蓝牙应用? ① 之前有没有接触Android蓝牙开发? ② 蓝牙设备固件是公司自己的吗? ③ 有没有蓝牙固件和蓝牙应用的文档和Demo? ④ 具 ...

  2. Android 低功耗蓝牙开发

    初识低功耗蓝牙 Android 4.3(API Level 18)开始引入Bluetooth Low Energy(BLE,低功耗蓝牙)的核心功能并提供了相应的 API, 应用程序通过这些 API 扫 ...

  3. Android低功耗蓝牙开发

    BLE中,设备分为中心设备(central)和外围设备(peripheral) 中心设备就是你的手机,外围设备就是智能手环一类的东西.开发BLE的应用都得遵守Generic Attribute Pro ...

  4. 【Android】蓝牙开发——BLE(低功耗蓝牙)(附完整Demo)

    目录 目录 前言 一.相关概念介绍 二.实战开发 三.项目演示 四.Demo案例源码地址 五.更新记录 1.2020/12/29 :修改 setupService()中错误 2.2021/05/14 ...

  5. Android笔记---蓝牙开发经典蓝牙和低功耗蓝牙

    目录 前言 一般开发步骤 相关API介绍 一.通用API 1.BluetoothAdapter 2.BluetoothDevice 二.经典蓝牙(BT)API 1.BluetoothSocket 2. ...

  6. android 连接蓝牙电子秤_电子秤蓝牙双模通讯Android低功耗蓝牙(蓝牙4.0)BLE开发(上)...

    电子秤蓝牙双模通讯Android低功耗蓝牙(蓝牙4.0)BLE开发(上) 前段时间,公司项目用到了手机APP和蓝牙设备的通讯开发,这里也正好对低功耗蓝牙(蓝牙4.0及以后标准)的开发,做一个总结. 蓝 ...

  7. Android BLE低功耗蓝牙开发

    啦啦啦在上一个项目中有用到BLE低功耗蓝牙开发,当时baidu google了很多资料,但大多数都是千篇一律,英文文档我这种渣渣又看不懂...总之刚开始查的很痛苦.所以要把自己的踩坑之路写下来记录下, ...

  8. Android低功耗蓝牙(BLE)开发(二)

    在上一篇文章Android低功耗蓝牙(BLE)开发(一)中我们了解了BLE的相关概念,这里我们来实际用代码演示安卓进行BLE连接和通讯的功能.本文代码基于Android5.0以上(API 21) 1. ...

  9. 使用BleLib的轻松搞定Android低功耗蓝牙Ble 4.0开发详解

    转载请注明来源: http://blog.csdn.net/kjunchen/article/details/50909410 使用BleLib的轻松搞定Android低功耗蓝牙Ble 4.0开发详解 ...

最新文章

  1. 数字图像处理——第十章 图像分割
  2. LeetCode 104. Maximum Depth of Binary Tree--二叉树高度--递归或迭代--C++,Python解法
  3. 11:菜单自动化软件部署经典案例
  4. JVM 的 工作原理,层次结构 以及 GC工作原理
  5. First、FirstOrDefault、Single、SingleOrDefault 的区别
  6. 在计算机桌面上添加小工具日历,实用桌面小工具时钟日历在win7中的添加方法...
  7. BZOJ1901:Zju2112 Dynamic Rankings——题解
  8. 为传递函数自动设定PID参数——pidtune学习笔记
  9. await原理 js_深入浅出node.js异步编程 及async await原理
  10. vb还是python强大-Python可以代替vb吗
  11. 人工智能的发展_人工智能发展带来的机遇
  12. Qt 学习之路 2(84):Repeater
  13. centeros 卸载mysql_完全卸载MySql
  14. 音响在线测试软件,汽车音响调音在线大师班(1):调音第一步,RTA检测播放表现...
  15. 扫线法快速判断凹多边形相交
  16. Django 搭建知乎热榜 API
  17. ps修改图像像素压缩图片大小
  18. (黑)群晖系统 ds photo 相机自动备份 无法识别DICM下的Camera解决方案
  19. java 获取mac字体_Mac OS X上的Java App无法正确打印字体
  20. 传统产业如何进行数字化转型

热门文章

  1. 关于公钥与私钥的一点看法
  2. 线程和进程的区别是什么?
  3. GSM 劫持短信验证码盗刷引关注:手机处于 2G 网络要小心了
  4. 深度学习应用篇-自然语言处理[10]:N-Gram、SimCSE介绍,更多技术:数据增强、智能标注、多分类算法、文本信息抽取、多模态信息抽取、模型压缩算法等
  5. 12否: 互励互教式的儿童视频网站
  6. LRU 缓存机制实现:哈希表 + 双向链表
  7. jQuery动态粒子效果
  8. 关于FPR和FNR (I类错误和II类错误)
  9. 6大顶级自学资源网站!不甘现状,学无止境
  10. [Eclipse插件开发-001] SWT/JFACE布局入门总结