Q:

When is physically a BLE connection is establishing? by calling establish connection() ? or calling the first characteristic after it?

I'm actually get confused from answers posted in other questions related to 'establishconnection()' and related discussions. Since I started working with a low energy BLE device connetion establishment to my App, I'm having a doubt about the physical communication establishment between App and Device. In my program I'm calling the establishconnection() before reading a characteristic. But I'm facing some connection issue always between the app and device during syncing after it. So I need to check the connection procedure once more deeply with my device. So can you please give me an exact point of code from the above points where the physical connection to the BLE Device is actually establishing from the app.

A:

There are several ways to find out when the exact moment of connection happens. This may be done on several levels:
Android default logs
Usually when connecting to a BLE peripheral a specific line is visible in the logcat:

D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=00:00:00:00:00:00

RxAndroidBle logs
One can set RxBleLog.setLogLevel(RxBleLog.VERBOSE) which would make the library internal logs visible. The moment that the library is informed by the system that the connection is established is marked with log:

D/RxBle#BluetoothGatt: onConnectionStateChange newState=2 status=0

Low level ACL broadcast
Most Android OSes do broadcast information when a low level Bluetooth connection is established. To get access to it a BroadcastReceiver must be registered:
Context context = /* your Context */;
IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED);
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        final BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        Log.d("Connected", "BluetoothDevice[macAddress=" + bluetoothDevice.getAddress() + ']');
    }
};
context.registerReceiver(broadcastReceiver, intentFilter);

This would trigger the below log:

D/Connected: BluetoothDevice[macAddress=00:00:00:00:00:00]

