1

I am writing an IOT based (BLE) Firemonkey app and I need to check that Bluetooth adapter is Enabled or not for both iOS and Android.

I've found a source here but it is only for android (like many others), but I need a cross platform solution.

Alper
  • 1,085
  • 3
  • 20
  • 39
  • 2
    Look at the properties of [`System.Bluetooth.TBluetoothLEManager`](http://docwiki.embarcadero.com/Libraries/en/System.Bluetooth.TBluetoothLEManager), such as [`ConnectionState`](http://docwiki.embarcadero.com/Libraries/en/System.Bluetooth.TBluetoothLEManager.ConnectionState) and [`CurrentAdapter`](http://docwiki.embarcadero.com/Libraries/en/System.Bluetooth.TBluetoothLEManager.CurrentAdapter). – Remy Lebeau Sep 16 '19 at 04:30
  • @RemyLebeau thank you so much to direct me to the right solution.. – Alper Sep 16 '19 at 09:26

1 Answers1

0

I've found a proper solution on here.

uses System.Bluetooth;

function IsBluetoothLEAdapterEnabled: Boolean;
var
  manager: TBluetoothLEManager;
  adapt: TBluetoothLEAdapter;
begin
  Result := False;
  try
    manager := TBluetoothLEManager.CreateInstance;
  except
    exit;
  end;

  try
    adapt := manager.CurrentAdapter;
  except
    exit;
  end;

  try
    if adapt.State = TBluetoothAdapterState.On then
    begin
      // BluetoothLE Adapter was found
      Result := True;
      exit;
    end;
  except
    exit;
  end;
end;

end execute like below

  if IsBluetoothLEAdapterEnabled then
    ShowMessage('BluetoothLE ON')
  else
    ShowMessage('BluetoothLE OFF');
Alper
  • 1,085
  • 3
  • 20
  • 39