Android10蓝牙服务log,Android蓝牙日志记录填满了logcat

我使用蓝牙聊天示例作为实现从手机到嵌入式设备的BT连接的起点。 我能够成功连接到设备,但一旦建立连接,logcat就会因大量的日志记录而被覆盖。 第一次使用BT聊天应用程序手机打电话时,我没有看到这种types的日志记录。

这是一遍又一遍的重复。 它基本上使logcat无法使用。 到目前为止,我还没有find一种方法来配置日志记录或为什么它记录这么多。 任何见解将不胜感激。03-08 14:29:04.941: DEBUG/BluetoothSocket.cpp(11422): availableNative 03-08 14:29:04.957: DEBUG/BluetoothSocket(11422): available 03-08 14:29:04.957: DEBUG/BluetoothSocket.cpp(11422): availableNative 03-08 14:29:04.971: DEBUG/BluetoothSocket(11422): available 03-08 14:29:04.976: DEBUG/BluetoothSocket.cpp(11422): availableNative 03-08 14:29:04.989: DEBUG/BluetoothSocket(11422): available 03-08 14:29:04.991: DEBUG/BluetoothSocket.cpp(11422): availableNative 03-08 14:29:05.016: DEBUG/BluetoothSocket(11422): available 03-08 14:29:05.016: DEBUG/BluetoothSocket.cpp(11422): availableNative 03-08 14:29:05.034: DEBUG/BluetoothSocket(11422): available 03-08 14:29:05.036: DEBUG/BluetoothSocket.cpp(11422): availableNative 03-08 14:29:05.050: DEBUG/BluetoothSocket(11422): available 03-08 14:29:05.051: DEBUG/BluetoothSocket.cpp(11422): availableNative 03-08 14:29:05.066: DEBUG/BluetoothSocket(11422): available 03-08 14:29:05.066: DEBUG/BluetoothSocket.cpp(11422): availableNative 03-08 14:29:05.081: DEBUG/BluetoothSocket(11422): available 03-08 14:29:05.081: DEBUG/BluetoothSocket.cpp(11422): availableNative 03-08 14:29:05.086: DEBUG/(2419): jw_if_rfcomm_cl_cback: jw_if_rfcomm_cl_cback event=BTA_JV_RFCOMM_READ_EVT 03-08 14:29:05.086: DEBUG/(2419): jv_forward_data_to_jni: BTA_JV_RFCOMM_DATA_IND_EVT bta hdl 2 03-08 14:29:05.086: DEBUG/(2419): bts_log_tstamps_us: [update stats] ts 1263504, bta hdl 2, diff 01263504, tx_q 1 (1), rx_q 0 (0) 03-08 14:29:05.086: DEBUG/BLZ20_WRAPPER(11422): blz20_wrp_poll: transp poll : (fd 41) returned r_ev [POLLIN ] (0x1) 03-08 14:29:05.086: DEBUG/BLZ20_WRAPPER(11422): blz20_wrp_poll: return 1 03-08 14:29:05.086: DEBUG/BLZ20_WRAPPER(11422): blz20_wrp_read: read 122 bytes out of 1024 on fd 41 03-08 14:29:05.101: DEBUG/BluetoothSocket(11422): read 03-08 14:29:05.101: DEBUG/BluetoothSocket.cpp(11422): readNative 03-08 14:29:05.101: DEBUG/ASOCKWRP(11422): asocket_read 03-08 14:29:05.106: INFO/BLZ20_WRAPPER(11422): blz20_wrp_poll: nfds 2, timeout -1 ms 03-08 14:29:05.117: DEBUG/BluetoothSocket(11422): available 03-08 14:29:05.121: DEBUG/BluetoothSocket.cpp(11422): availableNative

在DDMS中,您可以使用调试,信息,错误,警告按钮来过滤掉内容,您还可以创建一个特殊的filter,仅显示您感兴趣的内容。不要认为有任何蓝牙设置可以关闭日志记录你可以用。

在使用我的Arduino Board +蓝牙适配器后,我尝试使用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

调用以下函数会导致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

这一定是一个错误,一个严重的错误:

Logcat有时只显示此调试打印 – 尽管我的代码总是遇到它

或者蓝牙芯片有时会松动……(更有可能)。

只是将日志级别从verbose转换为调试不会改变将大量数据传输到Logcat的事实,阻止所有正常日志……

我偶然发现了这个:3年后这个日志堵塞仍然存在 – 至少在我的三星GT-I8190(4.1.2)上。

罪魁祸首是mmInputStream.available()

解决这个问题的一种方法是不使用它的available()方法。 代替:

int bytesAvailable = mmInputStream.available(); if(bytesAvailable > 0) {...

您可以使用类似下面的代码来解决日志堵塞问题……

int i = -1; while((i=mmInputStream.read())!=-1) { char c=(char)i; // you can do your buffering here... Log.i("readBT","have char: "+c); }

下面的代码也适用于有这个讨厌的bug的手机。 它可能应该修改,因为它只是一个快速和肮脏的修复:

void beginListenForData() { final Handler handler = new Handler(); final byte delimiter = 10; //This is the ASCII code for a newline character stopWorker = false; readBufferPosition = 0; readBuffer = new byte[1024]; workerThread = new Thread(new Runnable() { public void run() { while(!Thread.currentThread().isInterrupted() && !stopWorker) { try { int i = -1; while((i=mmInputStream.read())!=-1) { byte b=(byte)i; Log.i("readBT","have byte: " + b); if ( (readBufferPosition >= 1023) || (b == delimiter) ) { byte[] encodedBytes = new byte[readBufferPosition]; System.arraycopy(readBuffer, 0, encodedBytes, 0, encodedBytes.length); final String data = new String(encodedBytes, "UTF-8"); readBufferPosition = 0; handler.post(new Runnable() { public void run() { myLabel.setText(data); } }); } else { readBuffer[readBufferPosition++] = b; } } } catch (IOException ex) { stopWorker = true; } } } }); workerThread.start(); }

“avaliableNative”具有详细优先权。 要删除消息(以及所有详细消息),请使用“*:D”参数作为最后一个logcat参数。 通过在软盘图标旁边的combobox中使用“debug”优先级,可以在Eclipse中实现类似的function。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值