@@ -1477,12 +1477,12 @@ private void connectAction(JSONArray args, CallbackContext callbackContext) {
14771477 if (obj != null ) {
14781478 autoConnect = obj .optBoolean ("autoConnect" , false );
14791479 }
1480-
14811480 connections .put (device .getAddress (), connection );
14821481
14831482 BluetoothGatt bluetoothGatt = null ;
14841483 if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .M ) {
1485- bluetoothGatt = device .connectGatt (cordova .getActivity ().getApplicationContext (), autoConnect , bluetoothGattCallback , BluetoothDevice .TRANSPORT_LE );
1484+ int transportMode = getTransportMode (obj );
1485+ bluetoothGatt = device .connectGatt (cordova .getActivity ().getApplicationContext (), autoConnect , bluetoothGattCallback , transportMode );
14861486 } else {
14871487 bluetoothGatt = device .connectGatt (cordova .getActivity ().getApplicationContext (), autoConnect , bluetoothGattCallback );
14881488 }
@@ -3658,6 +3658,23 @@ private UUID[] getServiceUuids(JSONObject obj) {
36583658 return uuids ;
36593659 }
36603660
3661+
3662+ private int getTransportMode (JSONObject obj ) {
3663+ int transportMode = 0 ;
3664+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
3665+ transportMode = BluetoothDevice .TRANSPORT_AUTO ;
3666+ }
3667+
3668+ if (obj != null && !obj .isNull ("transport" )) {
3669+ try {
3670+ transportMode = obj .getInt ("transport" );
3671+ } catch (JSONException e ) {
3672+ Log .e ("BLE" , "An exception occurred while transport connection parameter, fall back to: BluetoothDevice.TRANSPORT_AUTO" );
3673+ }
3674+ }
3675+ return transportMode ;
3676+ }
3677+
36613678 private String getAddress (JSONObject obj ) {
36623679 //Get the address string from arguments
36633680 String address = obj .optString (keyAddress , null );
0 commit comments