在Android中读取GATT特征的正确方法是什么? [英] What is the proper method for reading a GATT characteristic in Android?

查看:167
本文介绍了在Android中读取GATT特征的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试读取Android API 18中的蓝牙低功耗GATT特性的值时,遇到了以下难题:检索存储在特性中的值的正确方法是什么?以及该操作应在堆栈的哪个级别进行?

In attempting to read the value of a Bluetooth Low-Energy GATT characteristic in the Android API 18, I came across the following dilemma: What is the proper way to retrieve the value stored in a characteristic? And at which level of the stack should this action take place?

在进行自己的研究时,我偶然发现了我所知道的两种可能的方法:

In conducting my own research, I stumbled upon what I understand are two possible methods:


  • BluetoothGatt .readCharacteristic(BluetoothGattCharacteristic特性)

  • BluetoothGattCharacteristic .getValue()

  • BluetoothGatt.readCharacteristic(BluetoothGattCharacteristic characteristic)
  • BluetoothGattCharacteristic.getValue()

public void onClick(View v){        
    byteValue = mBTValueCharacteristic.getValue();
    if ((byteValue[0] & 0x01) == 1)
        byteValue[0] = 0x00;
    else
        byteValue[0] = 0x01;

    mBTValueCharacteristic.setValue(byteValue);
    mBTGatt.writeCharacteristic(mBTValueCharacteristic);
}


以上是原始内容代码导致我遇到这个问题。在其中,我尝试读取特征的值,并使用按钮简单地切换其状态。

Above is the original code which led me to this issue. In it, I attempt to read the value of a characteristic, and simply toggle its state using a button.

推荐答案

BluetoothGatt.readCharacteristic(BluetoothGattCharacteristic characteristic)

此函数正在更新您的BluetoothGattCharacteristic对象(在您的Android设备上)使用来自蓝牙的特征值。

This function is updating your BluetoothGattCharacteristic object (on your Android device) using characteristic value from the Bluetooth .

BluetoothGattCharacteristic.getValue()

此函数只是BluetoothGattCharacteristic对象的getter函数。 android和蓝牙设备之间没有任何交易。

This function is just a getter function of the BluetoothGattCharacteristic object. There is not any transaction between android and the bluetooth device.

这篇关于在Android中读取GATT特征的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆