@@ -71,6 +71,7 @@ public class AirDataBridgeApplication extends Application {
71
71
72
72
boolean StoragePermissionChecked = false ;
73
73
boolean StoragePermissionGranted = false ;
74
+ boolean BluetoothAutoReconnect = true ; // Auto reconnect if disconnected
74
75
75
76
boolean StatusViewEnabled = false ; // If true, the status updates are enabled
76
77
boolean ForceRemoteLST = true ; // If true, ask $FMQ,LST also if recording
@@ -120,6 +121,14 @@ public void setStoragePermissionGranted(boolean storagePermissionGranted) {
120
121
StoragePermissionGranted = storagePermissionGranted ;
121
122
}
122
123
124
+ public boolean isBluetoothAutoReconnect () {
125
+ return BluetoothAutoReconnect ;
126
+ }
127
+
128
+ public void setBluetoothAutoReconnect (boolean bluetoothAutoReconnect ) {
129
+ BluetoothAutoReconnect = bluetoothAutoReconnect ;
130
+ }
131
+
123
132
public boolean isStatusViewEnabled () {
124
133
return StatusViewEnabled ;
125
134
}
@@ -601,8 +610,8 @@ public void onBluetoothHelperConnectionStateChanged(BluetoothHelper bluetoothhel
601
610
if (isConnected ) {
602
611
BluetoothConnectionStatus = EventBusMSG .BLUETOOTH_CONNECTED ;
603
612
EventBus .getDefault ().post (EventBusMSG .BLUETOOTH_CONNECTED );
604
- mBluetooth .SendMessage ("$HBQ,AirDataBridge,0.4" );
605
- mBluetooth .SendMessage ("$HBQ,AirDataBridge,0.4" );
613
+ mBluetooth .SendMessage ("$HBQ,AirDataBridge," + BuildConfig . VERSION_NAME );
614
+ mBluetooth .SendMessage ("$HBQ,AirDataBridge," + BuildConfig . VERSION_NAME );
606
615
startCommTimeout ();
607
616
Log .w ("myApp" , "[#] AirDataBridgeApplication.java - BLUETOOTH_CONNECTED" );
608
617
// Do something
@@ -613,7 +622,7 @@ public void onBluetoothHelperConnectionStateChanged(BluetoothHelper bluetoothhel
613
622
//}
614
623
//Log.w("myApp", "[#] AirDataBridgeApplication.java - EventBusMSG.REMOTE_UPDATE_LOGLIST");
615
624
// Auto reconnect
616
- if (BluetoothConnectionStatus != EventBusMSG .BLUETOOTH_OFF ) {
625
+ if (( BluetoothConnectionStatus != EventBusMSG .BLUETOOTH_OFF ) && ( BluetoothAutoReconnect ) ) {
617
626
BluetoothConnectionStatus = EventBusMSG .BLUETOOTH_CONNECTING ;
618
627
EventBus .getDefault ().post (EventBusMSG .BLUETOOTH_CONNECTING );
619
628
mBluetooth .Connect (BluetoothDeviceName );
@@ -655,6 +664,23 @@ public void onTerminate() {
655
664
@ Subscribe
656
665
public void onEvent (Short msg ) {
657
666
switch (msg ) {
667
+ case EventBusMSG .START_APP :
668
+ if (!BluetoothAutoReconnect ) {
669
+ BluetoothAutoReconnect = true ;
670
+ if (mBluetoothAdapter .isEnabled ()) {
671
+ BluetoothConnectionStatus = EventBusMSG .BLUETOOTH_CONNECTING ;
672
+ EventBus .getDefault ().post (EventBusMSG .BLUETOOTH_CONNECTING );
673
+ mBluetooth .Connect (BluetoothDeviceName );
674
+ } else {
675
+ BluetoothConnectionStatus = EventBusMSG .BLUETOOTH_OFF ;
676
+ EventBus .getDefault ().post (EventBusMSG .BLUETOOTH_OFF );
677
+ }
678
+ }
679
+ break ;
680
+ case EventBusMSG .EXIT_APP :
681
+ BluetoothAutoReconnect = false ;
682
+ mBluetooth .Disconnect ();
683
+ break ;
658
684
case EventBusMSG .STORAGE_PERMISSION_GRANTED :
659
685
StoragePermissionGranted = true ;
660
686
// Create folder if not exists
0 commit comments