0

I can't get requestConnectionPriority called correctly in Delphi Alexandria 11.3 FMX for Andoid BLE?

I actually assumed that the following code is sufficient to get the requestConnectionPriority. Androidapi.JNI.Bluetooth is included in uses and declared in Androidapi.JNI.Bluetooth.pas like this:

TJBluetoothGatt = class(TJavaGenericImport<JBluetoothGattClass, JBluetoothGatt>) end;

Now here is my code:

var
  JBluetoothGatt: TJBluetoothGatt; // requestConnectionPriority added in API level 21
begin
  JBluetoothGatt.Create;
 
 JBluetoothGatt.Wrap(self).requestConnectionPriority(JBluetoothGatt.JavaClass.CONNECTION_PRIORITY_HIGH); // this is nonsense but all function calls are visible, why ????
  JBluetoothGatt.Free;
end;

I would have expected more of a function like this now:

JBluetoothGatt.requestConnectionPriority(CONNECTION_PRIORITY_HIGH);

JBluetoothGatt has no functions. Only wrap lets me access the functions (list). I have no idea what AJINIObjectID or IJavaInstance is supposed to be, with is to call Wrap.

Anyway, I'm sure it is to act completely different. What is the right way?

4
  • You don't actually create an instance of TJBluetoothGatt (which you're doing wrong anyway) - an instance of JBluetoothGatt is returned when you call connectGatt on an instance of JBluetoothDevice. I expect you would call requestConnectionPriority once you've done that. It might help you understand how it works by looking at the System.Android.Bluetooth unit Sep 22 at 7:54
  • Also, the call would look like this: requestConnectionPriority(TJBluetoothGatt.JavaClass.CONNECTION_PRIORITY_HIGH) (you are missing a T). It's not nonsense - it's how the Java bridge works Sep 22 at 7:58
  • Hello Dave, Thanks for your help. But I'm afraid it's not enough. Unfortunately, the FMX is completely new material for me. I tried to call requestConnectionPriority() after the device is connected and the notification is switched on. like this: ADevice is the connected device. const ADevice: TBluetoothLEDevice TJBluetoothGatt.Wrap(ADevice).requestConnectionPriority(TJBluetoothGatt.JavaClass.CONNECTION_PRIORITY_LOW) ; Unfortunately, my calls are aborted with an error. Maybe you can show me the complete functioncall.
    – kdu300
    Sep 25 at 14:41
  • The code in your comment is incorrect, since TBluetoothLEDevice is a Delphi class, and you cannot use TJBluetoothGatt.Wrap with it, not to mention that it does not even make sense. As per my earlier comment: an instance of JBluetoothGatt is returned when you call connectGatt on an instance of JBluetoothDevice. If all this is new, that is why I suggested looking at the Delphi source to learn from it. Sep 25 at 20:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.