Javascript Android版本react本机应用程序仅在重新启动应用程序后将蓝牙连接到应用程序
我正在开发的应用程序的android版本需要连接蓝牙设备到应用程序(而不是设备)。首先,我们扫描设备:Javascript Android版本react本机应用程序仅在重新启动应用程序后将蓝牙连接到应用程序,javascript,android,react-native,bluetooth,react-native-android,Javascript,Android,React Native,Bluetooth,React Native Android,我正在开发的应用程序的android版本需要连接蓝牙设备到应用程序(而不是设备)。首先,我们扫描设备: setupScanCompleteListener() { this.scanCompleteListener = someBluetoothEventEmitter.addListener('someDeviceScanComplete', foundDevice => { console.log('AddDevicePage: setupSca
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();
}
});
}
始终会找到一个新的设备地址,这意味着someBluetoothManager.connectDeviceWithMacAddress
始终会被触发
在我无数次发出这个消息的时候,我从来没有看到过错误消息。但是,设置为检测设备何时连接的侦听器只有在我重新启动应用程序后才能持续工作。此外,我从未在console.logs中看到连接消息出错。我
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
所有其他日志都与该点相同