@@ -1477,10 +1477,15 @@ 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
1483- BluetoothGatt bluetoothGatt = device .connectGatt (cordova .getActivity ().getApplicationContext (), autoConnect , bluetoothGattCallback );
1482+ BluetoothGatt bluetoothGatt = null ;
1483+ if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .M ) {
1484+ int transportMode = getTransportMode (obj );
1485+ bluetoothGatt = device .connectGatt (cordova .getActivity ().getApplicationContext (), autoConnect , bluetoothGattCallback , transportMode );
1486+ } else {
1487+ bluetoothGatt = device .connectGatt (cordova .getActivity ().getApplicationContext (), autoConnect , bluetoothGattCallback );
1488+ }
14841489
14851490 connection .put (keyPeripheral , bluetoothGatt );
14861491 }
@@ -3653,6 +3658,23 @@ private UUID[] getServiceUuids(JSONObject obj) {
36533658 return uuids ;
36543659 }
36553660
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+
36563678 private String getAddress (JSONObject obj ) {
36573679 //Get the address string from arguments
36583680 String address = obj .optString (keyAddress , null );
0 commit comments