【发布时间】:2023-03-03 14:21:03
【问题描述】:
我的应用从蓝牙设备接收到永无止境的数据流。 我正在一个 while(true) 循环中读取这个流,并且可以在我的日志中看到读取的数据。 问题是,我的设备不再响应。是否有(希望)简单的方法让应用程序在后台读取流?
谢谢! 克里斯蒂安。
@博尔德: 抱歉,我不太了解 AsynkTask 类。 :( 你能帮我把这段代码放在后台吗? 非常感谢!
try {
while (true)
{
read = isBT.read(msgBuffer);
connected = true;
StringBuilder strBuffer = new StringBuilder();
for (int i = 0; i<read; i++)
{
int b = msgBuffer[i];
strBuffer.append(b);
}
Log.d(TAG,"++++++ Read "+ read + " Bytes: " + strBuffer.toString());
}
}
catch (IOException e) {
Log.d(TAG," +++ IOException ++++", e);
}
【问题讨论】:
标签: android inputstream android-asynctask