Android10蓝牙服务log,Android蓝牙日志填充logcat

在玩了我的Arduino Board + Bluetooth-Adapter之后,我尝试用MATT BELL'S BLOG实现蓝牙代码。问题是以下代码:

//final Handler handler = new Handler();

workerThread = new Thread(new Runnable()

{

public void run()

{

while(!Thread.currentThread().isInterrupted() && !stopWorker)

{

try {

int bytesAvailable = mmInputStream.available();

if(bytesAvailable > 0)

{

//Log.d(TAG,"bytesAvailable: "+bytesAvailable + " readBufferPosition: "+readBufferPosition);

byte[] packetBytes = new byte[bytesAvailable];

mmInputStream.read(packetBytes);

for(int i=0;i

{

byte delimiter = 0x0A; // /n bzw. LF

byte b = packetBytes[i];

if(b == delimiter)

{

byte[] encodedBytes = new byte[readBufferPosition];

System.arraycopy(readBuffer, 0, encodedBytes, 0, encodedBytes.length);

final String data = new String(encodedBytes, "US-ASCII");

//final String data = new String(readBuffer);

readBufferPosition = 0;

Log.d(TAG,""+data);

// //The variable data now contains our full command

// handler.post(new Runnable()

// {

// public void run()

// {

// //myLabel.setText(data);

// Log.d(TAG,""+data);

// }

// });

}

else

{

readBuffer[readBufferPosition++] = b;

}

}

}

} catch (Exception e) {

Log.d(TAG,"Exeption 2: "+e.getMessage());

stopWorker = true;

}

}

}

});

workerThread.start();

调用以下函数会导致logCat中出现巨大的垃圾邮件

int bytesAvailable = mmInputStream.available();

logcat的:

PS:时间戳实际上是固定版本。不使用此修复程序将导致垃圾邮件每5毫秒有效地阻止我的整个日志

03-17 18:43:06.615: VERBOSE/BluetoothSocket.cpp(8871): availableNative

03-17 18:43:06.715: VERBOSE/BluetoothSocket.cpp(8871): availableNative

03-17 18:43:06.820: VERBOSE/BluetoothSocket.cpp(8871): availableNative

03-17 18:43:06.920: VERBOSE/BluetoothSocket.cpp(8871): availableNative

03-17 18:43:07.020: VERBOSE/BluetoothSocket.cpp(8871): availableNative

03-17 18:43:07.120: VERBOSE/BluetoothSocket.cpp(8871): availableNative

03-17 18:43:07.220: VERBOSE/BluetoothSocket.cpp(8871): availableNative

03-17 18:43:07.320: VERBOSE/BluetoothSocket.cpp(8871): availableNative

03-17 18:43:07.420: VERBOSE/BluetoothSocket.cpp(8871): availableNative

03-17 18:43:07.520: VERBOSE/BluetoothSocket.cpp(8871): availableNative

03-17 18:43:07.620: VERBOSE/BluetoothSocket.cpp(8871): availableNative

03-17 18:43:07.725: VERBOSE/BluetoothSocket.cpp(8871): availableNative

03-17 18:43:07.825: VERBOSE/BluetoothSocket.cpp(8871): availableNative

03-17 18:43:07.925: VERBOSE/BluetoothSocket.cpp(8871): availableNative

03-17 18:43:08.025: VERBOSE/BluetoothSocket.cpp(8871): availableNative

我目前的修复是在while循环结束时添加以下代码,从而减少垃圾邮件。

try {

Thread.sleep(100);

} catch (Exception e) {

Log.d(TAG,"Exception Thread.sleep()");

}

我希望这能帮助一些有类似问题的人。

编辑:目前我不得不将睡眠时间减少到10毫秒bam ..垃圾邮件

03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative

03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative

03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative

03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative

03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative

03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative

03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative

03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative

03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative

03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值