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?
TJBluetoothGatt
(which you're doing wrong anyway) - an instance ofJBluetoothGatt
is returned when you callconnectGatt
on an instance ofJBluetoothDevice
. I expect you would callrequestConnectionPriority
once you've done that. It might help you understand how it works by looking at theSystem.Android.Bluetooth
unitrequestConnectionPriority(TJBluetoothGatt.JavaClass.CONNECTION_PRIORITY_HIGH)
(you are missing a T). It's not nonsense - it's how the Java bridge worksTBluetoothLEDevice
is a Delphi class, and you cannot useTJBluetoothGatt.Wrap
with it, not to mention that it does not even make sense. As per my earlier comment: an instance ofJBluetoothGatt
is returned when you callconnectGatt
on an instance ofJBluetoothDevice
. If all this is new, that is why I suggested looking at the Delphi source to learn from it.