Android 无需按下按钮即可显示新的可编辑数据
我正在尝试显示蓝牙低能量(BLE)服务发布的新数据。这是使用BluetoothLeService中的setCharacteristicNotification()回调完成的,如下所示:Android 无需按下按钮即可显示新的可编辑数据,android,bluetooth-lowenergy,Android,Bluetooth Lowenergy,我正在尝试显示蓝牙低能量(BLE)服务发布的新数据。这是使用BluetoothLeService中的setCharacteristicNotification()回调完成的,如下所示: mBluetoothLeService.setCharacteristicNotification(mNotifyCharacteristic, true); ,其中mNotifyCharacteristic是BluetoothGattCharacteristic对象 这个回调通常在onClickLis
mBluetoothLeService.setCharacteristicNotification(mNotifyCharacteristic,
true);
,其中mNotifyCharacteristic是BluetoothGattCharacteristic对象
这个回调通常在onClickListener中触发,但我正在尝试自动显示新数据,而不必按UI上的按钮。我尝试在onResume()中调用此方法,但它似乎没有任何作用:
@Override
protected void onResume() {
super.onResume();
...
if(mBluetoothLeService != null){
mBluetoothLeService.setCharacteristicNotification(mNotifyCharacteristic,
true);
}
}
我是一名经验丰富的Android开发者,但对蓝牙技术还不熟悉,所以我在这里有点迷茫
有人能帮忙吗
干杯,
Tony为什么您需要使用BluetoothLeScannerCompat作为扫描设备。通过使用这个你可以得到广告数据。我解决了这个问题。我需要一个初始onclick侦听器来知道要显示哪些数据。我在这个侦听器中放置了一个可运行对象,现在可以在发布新数据时自动更新显示