最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

bluetooth lowenergy - Ble Retry in 3 attempts every 5 sec delay in android not working - Stack Overflow

programmeradmin2浏览0评论

Hi want implement Ble retry ,if it is more than 3 times attempts every 5 sec delay.

Below code not working it is calling only once.

else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                    // disconnected from the GATT Server
                    if(connectionRetries < 3) {
                        Log.d("data uri","mRetries"+mRetries);
                        connectionRetries ++;
                        try {
                            connectToBleGattServer(bleDevice,activity);
                            Thread.sleep(5000L);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }

Connectgattserver method:

public boolean connectToBleGattServer(BluetoothDevice bleDevice, Activity context) {
        if (bleDevice == null || bluetoothGattCallback == null) return false;
        try {
            if (Build.VERSION.SDK_INT >= 23) {
                Log.d("PesBleDevice", "New method of connection is called with transport value of 2..");
                bluetoothGatt = bleDevice.connectGatt(context, false, bluetoothGattCallback, 2);
                connectionStateChangeListenerQueue.add(new ENHOBleCallback());
                Log.d("PesBleDevice", "Ble Connected");
            } else {
                bluetoothGatt = bleDevice.connectGatt(context, false, bluetoothGattCallback);
                connectionStateChangeListenerQueue.add(new ENHOBleCallback());
                Log.d("PesBleDevice", "New method of connection is called...");
            }
            return true;
        } catch (Exception e) {
            Log.d("PesBleDevice", "Unable to connect.");
            return false;
        }
    }
发布评论

评论列表(0)

  1. 暂无评论