簡體   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