@@ -471,7 +471,7 @@ Bluetooth._disconnect = function(gatt) {
471471// note that this doesn't make much sense without scanning first
472472Bluetooth . connect = function ( arg ) {
473473 return new Promise ( function ( resolve , reject ) {
474- try {
474+ try {
475475 // or macaddress..
476476 if ( ! arg . UUID ) {
477477 reject ( "No UUID was passed" ) ;
@@ -482,20 +482,30 @@ Bluetooth.connect = function (arg) {
482482 reject ( "Could not find peripheral with UUID " + arg . UUID ) ;
483483 } else {
484484 console . log ( "Connecting to peripheral with UUID: " + arg . UUID ) ;
485- var bluetoothGatt = bluetoothDevice . connectGatt (
486- utils . ad . getApplicationContext ( ) , // context
487- false , // autoconnect
488- new Bluetooth . _MyGattCallback ( /* TODO pass in onWhatever function */ )
489- ) ;
490- // TODO (fill, and use this object in disconnect() as well)
485+
486+ var bluetoothGatt ;
487+ if ( android . os . Build . VERSION . SDK_INT < 23 /*android.os.Build.VERSION_CODES.M */ ) {
488+ bluetoothGatt = bluetoothDevice . connectGatt (
489+ utils . ad . getApplicationContext ( ) , // context
490+ false , // autoconnect
491+ new Bluetooth . _MyGattCallback ( /* TODO pass in onWhatever function */ )
492+ ) ;
493+ } else {
494+ bluetoothGatt = bluetoothDevice . connectGatt (
495+ utils . ad . getApplicationContext ( ) , // context
496+ false , // autoconnect
497+ new Bluetooth . _MyGattCallback ( /* TODO pass in onWhatever function */ ) ,
498+ android . bluetooth . BluetoothDevice . TRANSPORT_LE // 2
499+ ) ;
500+ }
501+
491502 Bluetooth . _connections [ arg . UUID ] = {
492503 state : 'connecting' ,
493504 onConnected : arg . onConnected ,
494505 onDisconnected : arg . onDisconnected ,
495506 device : bluetoothGatt // TODO rename device to gatt?
496507 } ;
497508 }
498- // resolve();
499509 } catch ( ex ) {
500510 console . log ( "Error in Bluetooth.connect: " + ex ) ;
501511 reject ( ex ) ;
0 commit comments