Skip to content

Commit 4c2aca2

Browse files
authored
Merge pull request #631 from mattkhaw/master
Fix isAdvertising to update correctly
2 parents 094cb48 + c620ec4 commit 4c2aca2

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/android/BluetoothLePlugin.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,14 +757,16 @@ private void stopAdvertisingAction(JSONArray args, CallbackContext callbackConte
757757
if (advertiser == null) {
758758
JSONObject returnObj = new JSONObject();
759759

760-
addProperty(returnObj, "error", "startAdvertising");
760+
addProperty(returnObj, "error", "stopAdvertising");
761761
addProperty(returnObj, "message", "Advertising isn't supported");
762762

763763
callbackContext.error(returnObj);
764764
return;
765765
}
766766

767767
advertiser.stopAdvertising(advertiseCallback);
768+
769+
if (isAdvertising) isAdvertising = false;
768770

769771
JSONObject returnObj = new JSONObject();
770772
addProperty(returnObj, "status", "advertisingStopped");
@@ -2785,6 +2787,9 @@ public void onReceive(Context context, Intent intent) {
27852787
}
27862788
scanCallbackContext = null;
27872789

2790+
// Reset isAdvertising when adapter is off (if STATE_TURNING_OFF doesn't trigger)
2791+
if (isAdvertising) isAdvertising = false;
2792+
27882793
gattServer = null;
27892794

27902795
pluginResult = new PluginResult(PluginResult.Status.OK, returnObj);
@@ -2795,7 +2800,11 @@ public void onReceive(Context context, Intent intent) {
27952800

27962801
break;
27972802
case BluetoothAdapter.STATE_TURNING_OFF:
2798-
if(gattServer != null) gattServer.close();
2803+
// Reset isAdvertising when adapter is turning off
2804+
if (isAdvertising) isAdvertising = false;
2805+
2806+
// Make sure gattServer is not null (in case this triggers when it is null)
2807+
if (gattServer != null) gattServer.close();
27992808
break;
28002809
case BluetoothAdapter.STATE_ON:
28012810

0 commit comments

Comments
 (0)