繁体   English   中英

如何在BLE中断开连接和重新连接过程的延迟?

[英]How can I make delay for disconnection and reconnection process in BLE?

我在断开连接和连接过程中遇到问题。 假设我有一个按钮,可用来断开以前的低功耗蓝牙设备并与新的BLE设备连接。 通常,断开连接过程大约需要500ms-> 1秒,因此,我必须进行一个延迟过程,目的是等待断开连接过程完成。 然后,我将调用新的连接过程。 这是我的代码

public void onClickButton( View v){
     //Disconnect previous 
     mBluetoothLeService.disconnect();
     //Need to wait here...
     //Connect with new BLE
     mBluetoothLeService.connect(mDeviceAddress);
}

您认为Timer,Handler或Thread是我的最佳选择吗? 谢谢大家

这是我使用计时器的解决方案

            final ProgressDialog  waitProgressDialog = ProgressDialog.show(this, "Please wait ...", "Disconnecting ...", true);
            waitProgressDialog.setCancelable(true);
            new CountDownTimer(500,100) {
                public void onTick(long millisUntilFinished) {
                }
                public void onFinish() {
                    waitProgressDialog.dismiss();
                }
            }.start();

估计时间的方法似乎是错误的解决方案,因为它取决于连接参数,因为设备将等待确认外设已接收到命令,因此断开连接需要花费多长时间。

相反,只需等待onConnectionStateChange回调。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM