notifications - Android Ble 延迟通知

标签 notifications bluetooth-lowenergy delay

在 android BLE 上,我根据来自 BLE 设备的通知测量实时传感数据。默认情况下,我每秒获取 1 次通知数据。但是,我想在某个时间段内延迟从设备获取数据。下面是我的代码的屏幕截图。

  setNotificationCallback(mTXCharacteristic)
                .with(new TemperatureMeasurementDataCallback() {
                    @Override
                    public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
                        PrintLog.i(" "+TemperatureMeasurementParser.parse(data) + " °C");
                        //Toast.makeText(getContext(), " "+TemperatureMeasurementParser.parse(data)  + " °C", Toast.LENGTH_LONG).show();
                        //super.onDataReceived(device, data);
                        onTemperatureMeasurementReceived(device, Float.parseFloat(TemperatureMeasurementParser.parse(data)), TemperatureMeasurementCallback.UNIT_C, null, null);
                    }

                    @Override
                    public void onTemperatureMeasurementReceived(@NonNull final BluetoothDevice device,
                                                                 final float temperature, final int unit,
                                                                 @Nullable final Calendar calendar,
                                                                 @Nullable final Integer type) {
                        mCallbacks.onTemperatureMeasurementReceived(device, temperature, unit, calendar, type);
                    }

                    public void onTemperatureMeasurementReceived(@NonNull final BluetoothDevice device,
                                                                 final float temperature, final int unit,
                                                                 @Nullable final Calendar calendar,
                                                                 @Nullable final Integer type,  @Nullable final Integer batteryLevel) {
                        mCallbacks.onTemperatureMeasurementReceived(device, temperature, unit, calendar, type,batteryLevel);
                    }
                });


        requestMtu(260).enqueue();
        enableNotifications(mTXCharacteristic).enqueue();
        //sleep(10000).enqueue();

最佳答案

正在从遥感设备发送通知。因此,如果要延迟或改变接收传感数据的时间间隔,需要修改传感器中的代码。这是正确可靠的方法。或者,您可以在 Android 应用程序上启动计时器(例如每 10 秒一次)。当您从远程设备收到通知时,不要显示它们。相反,将它们存储在全局变量中。然后,当 10 秒计时器到期时,打印这些变量并重新启动计时器。

希望对您有所帮助。

关于notifications - Android Ble 延迟通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55457158/

相关文章:

jquery - 如何在asp.net中创建一次性通知系统

android - 从后台安排本地通知(Ionic + ngCordova)

ios - Xamarin.iOS 每天自动更改本地通知标题

ios - BLE Bond 表 iOS

java - 安卓蓝牙 : Identify the Characteristic Type?

c# - 调用 Task.Delay() 并在几分钟后询问还剩多少时间

ruby-on-rails - 在 Windows Vista 上发出任何 Rails 命令时出现延迟

android - 使用 setContent 时自定义通知崩溃

android - startLeScan 替换为当前 api

c# - Windows Workflow 4.5 延迟事件未持续