我正在编写一个涉及蓝牙低能量扫描的应用程序,我正面临一个奇怪的错误。 BLE扫描适用于大多数设备,但只要打开范围内的某个温度传感器,蓝牙就会在我的设备(Kindle Fire)上崩溃并关闭。扫描然后完全停止工作,直到我可以重新打开蓝牙。温度传感器未在ListView中显示已添加扫描设备,因此我不确定在崩溃之前是否发生了传感器的ScanCallback。有谁知道这个问题的可能原因?
这是我的ScanLeDevice()方法和ScanCallback:
private void scanLeDevice(final boolean enable) {
if (enable) {
scanning = true;
scanner.startScan(filterList, settings, mLeScanCallback);
scanPost();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
//Stop scanning after 10 seconds
scanLeDevice(false);
}
}, SCAN_PERIOD);
} else {
scanning = false;
scanner.stopScan(mLeScanCallback);
mHandler.removeCallbacksAndMessages(null);
// mBluetoothAdapter.stopLeScan(mLeScanCallback);
this.stopScan();
}
}
private ScanCallback mLeScanCallback =
new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
final int new_rssi = result.getRssi();
final BluetoothDevice new_device = result.getDevice();
runOnUiThread(new Runnable() {
@Override
public void run() {
// add to view
//TODO: add in check in UUIDs to make sure only temperature sensors are added
if (new_rssi > -90) {
adapter.addDevice(new_device, new_rssi);
adapter.notifyDataSetChanged();
}
}
});
}
};
以下是logcat的发现:
E/BTLD:##################################################################
E/BTLD: #
E/BTLD: # WARNING : BTU HCI(id=0) command timeout. opcode=0x2006
E/BTLD: #
E/BTLD:##################################################################
E/bt-hci: Num consecutive HCI Cmd tout =2 Restarting BT process
E/bt-btm: cannot interpret APCF callback status = 0, length = 1
E/BTLD: ##################################################################
E/BTLD: #
E/BTLD: # WARNING : BTU HCI(id=0) command timeout. opcode=0x2006
E/BTLD: #
E/BTLD: ##################################################################
E/bt-hci: Num consecutive HCI Cmd tout =2 Restarting BT process
E/BT_UTILS: bt_utils_set_pts_flag, pts_enable 0
E/bt_osi_config: config_new unable to open file '/etc/bluetooth/ble_stack.conf': No such file or directory
E/BT_UTILS: bt_utils_set_pts_flag, pts_enable 0
E/bt_osi_config: config_new unable to open file '/etc/bluetooth/ble_stack.conf': No such file or directory
E/[BT]: init_uart: Can't open serial port
E/bt_userial: userial_open unable to open serial port.
E/bt_userial: userial_write error writing to serial port: Bad file number 9
E/bt-btif: ...preload_wait_timeout (retried:0/max-retry:0)...
E/[BT]: thread_exit: pthread_mutex_unlock error
E/WifiStateMachine: sending event=NETWORK_STATE_CHANGED_ACTION, info=[state: CONNECTING/OBTAINING_IPADDR, reason: null, isAvailable: true]
E/BT_UTILS: bt_utils_set_pts_flag, pts_enable 0
E/bt_osi_config: config_new unable to open file
'/etc/bluetooth/ble_stack.conf': No such file or directory
E/bt-btm: BTM_SecRegister:p_cb_info->p_le_callback == 0xa3943529
E/bt-btm: BTM_SecRegister: btm_cb.api.p_le_callback = 0xa3943529
E/bt-btif: Calling BTA_HhEnable
E/bt-btif: btif_storage_get_adapter_property service_mask:0x2100028
E/bt-btif: btif_hf_upstreams_evt: Invalid index 8223
E/bt_h4: vendor lib postload completed