0

Hello I am new in Android BLE, I am connecting BLE device, in that if connection fails it will try to reconnect 5 times, if still connection failed, then it will show message to user that connection is FAILED other wise it will try 5 times

Below is my code

 else if (Utils.ACTION_DEVICE_DISCONNECTED.equals(action)) {
                Log.d(TAG, "onReceive: ACTION_DEVICE_DISCONNECTED");
                isDeviceConnected = false;
                if(!isOnceConnected && tryAgainToConnectCounter < NO_OFF_TIMES_TRY_TO_CONNECT) {
                   connectdevice();
                }else {
                    tryAgainToConnectCounter = 0;
                    generateToast(getResources()
                            .getString(R.string.strdisconnected));
                    if (progressDialog != null && progressDialog.isShowing()){
                        progressDialog.dismiss();
                    }
                    deviceDisconnectedMsg();
                }

            }

Now my problem is that when my phone is trying to connect with device & if connection failed, it is taking 18 seconds, in between.

I want to reduce that time, means my phone will try to connect only 5 seconds, and in 5 seconds if it is not possible, it should goes to DEVICE_DISCONNECTED & try to connect again

I have seen below link

Android BLE Connection time interval

but it is for after connection, data pass interval, I want when device is trying to connect

Anybody please help me how to resolve this

Thank you so much

Community
  • 1
  • 1
Siddhpura Amit
  • 14,534
  • 16
  • 91
  • 150
  • 1
    you have to manually wait for 5 sec, and check the state. If it is not connected, then you can `bluetoothGatt.close();` connection – Vladyslav Matviienko Dec 07 '16 at 09:12
  • Thanks @VladMatvienko, let me try this way – Siddhpura Amit Dec 07 '16 at 09:14
  • You will have to better define "failed to connect". If you mean the peripheral is unresponsive and causes a link layer timeout, Android's time out value is set to 20 seconds so it will take quite some long time to detect the error. You can't reconnect properly until this time out has passed. – Emil Dec 07 '16 at 13:31

0 Answers0