我正在处理的应用程序的android版本需要将蓝牙设备连接至该应用程序(不支持该设备)。首先,我们扫描设备:
setupScanCompleteListener() {
this.scanCompleteListener = someBluetoothEventEmitter.addListener('someDeviceScanComplete', foundDevice => {
console.log('AddDevicePage: setupScanCompleteListener: foundDevice: ', foundDevice);
// console.log('AddDevicePage: setupScanCompleteListener: devices: ' + foundDevice.deviceAddresses);
let newDeviceAddress = this.findNewDeviceAddress(foundDevice.deviceAddresses);
this.newDeviceAddress = newDeviceAddress;
if (newDeviceAddress) {
console.log('inside newDeviceAddress: ', newDeviceAddress);
this.setConnectTimeout();
someBluetoothManager.connectDeviceWithMacAddress(newDeviceAddress, error => {
console.log('Could not connectDeviceWithMacAddress: ', error)
});
this.props.addToTotalNumberofInitialDevices();
console.log('this is after someBluetoothManager.connectDeviceWithMacAddress gets fired: ', this.props);
}
else {
this.props.endSearchingForDeviceFunc();
console.log('No new devices found', this.props);
this.handleNoNewDevicesFound();
}
});
}
总是找到newDeviceAddress,这意味着someBluetoothManager.connectDeviceWithMacAddress
总是被触发。
在我已经解雇了百万次之后,我再也没有看到错误消息。但是,设置为检测设备何时连接的侦听器只能在我重新启动应用程序后才能始终运行。另外,我从没在console.logs中看到ERROR_ON_CONNECTING消息。我
setupDeviceStatusChangedListener() {
this.someDeviceStatusChanged = someBluetoothEventEmitter.addListener('someDeviceStatusChanged', event => {
console.log('someDeviceStatusChanged: event: ', event)
if (EventUtils.eventCodeEquals(event, 'CONNECTED')) {
console.log('right after device gets connected ', event)
this.handleDeviceConnected();
}
else if (EventUtils.eventCodeEquals(event, 'ERROR_ON_CONNECTING')) {
console.log('inside the else if block: ', event);
this.handleNoNewDevicesFound();
}
});
}
我已经比较了Android Studio中的日志,以查看第一次尝试连接与第二次尝试之间的区别。
第一次尝试连接时,我会在日志中看到此信息:
2019-02-25 15:39:54.257 23934-24032/com.someapp D/com.facebook.FacebookSdk: getGraphApiVersion: v3.0
2019-02-25 15:39:54.296 23934-24032/com.someapp D/TcpOptimizer: TcpOptimizer-ON
2019-02-25 15:39:54.327 23934-23934/com.someapp D/ApkSoSource: not allowing consideration of lib/armeabi-v7a/libfb.so: deferring to libdir
2019-02-25 15:39:54.328 23934-23934/com.someapp D/ApkSoSource: not allowing consideration of lib/armeabi-v7a/libfolly_json.so: deferring to libdir
2019-02-25 15:39:54.328 23934-23934/com.someapp D/ApkSoSource: not allowing consideration of lib/armeabi-v7a/libgifimage.so: deferring to libdir
2019-02-25 15:39:54.328 23934-23934/com.someapp D/ApkSoSource: not allowing consideration of lib/armeabi-v7a/libglog.so: deferring to libdir
2019-02-25 15:39:54.328 23934-23934/com.someapp D/ApkSoSource: not allowing consideration of lib/armeabi-v7a/libglog_init.so: deferring to libdir
2019-02-25 15:39:54.328 23934-23934/com.someapp D/ApkSoSource: not allowing consideration of lib/armeabi-v7a/libgnustl_shared.so: deferring to libdir
2019-02-25 15:39:54.328 23934-23934/com.someapp D/ApkSoSource: not allowing consideration of lib/armeabi-v7a/libicu_common.so: deferring to libdir
2019-02-25 15:39:54.328 23934-23934/com.someapp D/ApkSoSource: not allowing consideration of lib/armeabi-v7a/libimagepipeline.so: deferring to libdir
2019-02-25 15:39:54.329 23934-23934/com.someapp D/ApkSoSource: not allowing consideration of lib/armeabi-v7a/libjsc.so: deferring to libdir
2019-02-25 15:39:54.329 23934-23934/com.someapp D/ApkSoSource: not allowing consideration of lib/armeabi-v7a/libsomefittingjni.so: deferring to libdir
2019-02-25 15:39:54.329 23934-23934/com.someapp D/ApkSoSource: not allowing consideration of lib/armeabi-v7a/libprivatedata.so: deferring to libdir
2019-02-25 15:39:54.329 23934-23934/com.someapp D/ApkSoSource: not allowing consideration of lib/armeabi-v7a/libreactnativejni.so: deferring to libdir
2019-02-25 15:39:54.330 23934-23934/com.someapp D/ApkSoSource: not allowing consideration of lib/armeabi-v7a/libyoga.so: deferring to libdir
但是,第二次连接时,我看到了:
2019-02-25 15:47:45.626 25734-25734/com.someapp I/fb-UnpackingSoSource: dso store is up-to-date: /data/user/0/com.someapp/lib-main
,所有其他日志都与此相同。