Android 低功耗蓝牙开发(数据交互),Android入门教程

public 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 更新操作的状态

*/

@Override

public 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状态

*/

@Override

public void onServicesDiscovered(BluetoothGatt gatt, int status) {

super.onServicesDiscovered(gatt, status);

}

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

4. onCharacteristicRead

/**

  • 特性读取回调

  • @param gatt gatt

  • @param characteristic 特性

  • @param status gatt状态

*/

@Override

public 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状态

*/

@Override

public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {

super.onCharacteristicWrite(gatt, characteristic, status);

}

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

6. onCharacteristicChanged

/**

  • 特性改变回调

  • @param gatt gatt

  • @param characteristic 特性

*/

@Override

public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {

super.onCharacteristicChanged(gatt, characteristic);

}

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

7. onDescriptorRead

/**

  • 描述符获取回调

  • @param gatt gatt

  • @param descriptor 描述符

  • @param status gatt状态

*/

@Override

public 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状态

*/<

  • 23
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值