gpt4 book ai didi

android - 获取 GATT Android 中 BLE 特性的值

转载 作者:太空狗 更新时间:2023-10-29 16:37:40 27 4
gpt4 key购买 nike

我正在尝试使用以下代码读取特征并获取其值

private byte[] val;

mBluetoothLeService.readCharacteristic(characteristic);// reads it
val=characteristic.getValue();
String s=new String(val);

我的应用程序崩溃并显示错误“应用程序可能在其主线程上做了太多工作。”

我也试过

private String s;
mBluetoothLeService.readCharacteristic(characteristic);// reads it
s=characteristic.getStringValue(0);

但错误是一样的

我已经调试了我的代码以检查它是否获得了值

private String s;
mBluetoothLeService.readCharacteristic(characteristic);// reads it
s=characteristic.getStringValue(0);
system.out.println(s);

显示正确的值,但在将代码作为 Android 应用程序运行时。我得到了同样的错误。

最佳答案

如果我没记错的话,这可能是因为您在主线程上做了太多工作,您应该在单独的线程中或使用 Runnable 或 AsyncTask 进行繁重的处理。 This SO question might help you.

关于android - 获取 GATT Android 中 BLE 特性的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24710453/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com