app/src/main/java/com/example/alphabotandroid/SerialSocket.java
/**
     * connect-success and most connect-errors are returned asynchronously to listener
     */
connect-success and most connect-errors are returned asynchronously to listener
connect - success and most connect - errors are returned asynchronously to listener
void connect(com.example.alphabotandroid.SerialListener listener) throws IOException {
        if(connected || gatt != null)
            throw new IOException("already connected");
        canceled = false;
        this.listener = listener;
        context.registerReceiver(disconnectBroadcastReceiver, new IntentFilter(Constants.INTENT_ACTION_DISCONNECT));
        Log.d(TAG, "connect "+device);
        context.registerReceiver(pairingBroadcastReceiver, pairingIntentFilter);
        if (Build.VERSION.SDK_INT < 23) {
            Log.d(TAG, "connectGatt");
            gatt = device.connectGatt(context, false, this);
        } else {
            Log.d(TAG, "connectGatt,LE");
            gatt = device.connectGatt(context, false, this, BluetoothDevice.TRANSPORT_LE);
        }
        if (gatt == null)
            throw new IOException("connectGatt failed");
    }
void connect ( com . example . alphabotandroid . SerialListener listener ) throws IOException { if ( connected || gatt != null ) throw new IOException ( "already connected" ) ; canceled = false ; this . listener = listener ; context . registerReceiver ( disconnectBroadcastReceiver , new IntentFilter ( Constants . INTENT_ACTION_DISCONNECT ) ) ; Log . d ( TAG , "connect " + device ) ; context . registerReceiver ( pairingBroadcastReceiver , pairingIntentFilter ) ; if ( Build . VERSION . SDK_INT < 23 ) { Log . d ( TAG , "connectGatt" ) ; gatt = device . connectGatt ( context , false , this ) ; } else { Log . d ( TAG , "connectGatt,LE" ) ; gatt = device . connectGatt ( context , false , this , BluetoothDevice . TRANSPORT_LE ) ; } if ( gatt == null ) throw new IOException ( "connectGatt failed" ) ; }
connect-success and most connect-errors are returned asynchronously to listener
connect - success and most connect - errors are returned asynchronously to listener
// continues asynchronously in onPairingBroadcastReceive() and onConnectionStateChange()