Problem with EnableBluetooth() on Android.

Problem with EnableBluetooth() on Android.

I'm using Delphi 10.1 Berlin to make an app that communicates using Bluetooth LE.

On Android, if the user has turned off Bluetooth, I call TBluetoothLEManager.EnableBluetooth() to prompt them to turn Bluetooth on -- it pops up a dialog with "Deny" or "Allow" buttons, all of which works just fine.

The problem is that the call to EnableBluetooth() is non-blocking and returns right away, and I can't find anyway to tell when the user has closed the popup dialog. I've looked at the library source code and can see that it's creating a thread to show the dialog box and return right away, but I can't see anyway to get a callback when it closes. (The code I'm looking at is the DoEnableBluetooth method in System.Android.Bluetooth). Anyone have any ideas? TIA.

Comments

  1. You could subscribe to the TMessageResultNotification message, and check the RequestCode value for 2002, which corresponds to REQUEST_ENABLE_BT, which sadly is in the implementation section of System.Android.Bluetooth.pas. Then you could check if the BluetoothLE component's GetCurrentAdapter <> nil. This should work, but I have not tested it

    ReplyDelete
  2. Just to follow up -- David's suggestion worked just great.

    ReplyDelete
  3. It should be a feature, and I don't know why it isn't. Later today or tomorrow I'll submit a feature request if someone else hasn't done it first

    ReplyDelete

Post a Comment