We have found a workaround that works for us on both Android 11 and Android 12.
We have adapted the "JLocationListener" interface from the file Androidapi.JNI.Location.pas" as follows:
Delphi Code:
JLocationListener = interface(IJavaInstance)
['{D1CF3FB5-3BCB-4959-98D7-BD4D8F93D839}']
procedure onLocationChanged(location: JObject); cdecl;
procedure onProviderDisabled(provider: JString); cdecl;
procedure onProviderEnabled(provider: JString); cdecl;
procedure onStatusChanged(provider: JString; status: Integer; extras: JBundle); cdecl;
end;
and have modified the "TLocationListener" class in the "System.Android.Sensors.pas" file as follows:
Delphi Code:
TLocationListener = class(TJavaLocal, JLocationListener)
private
FLocationSensor: TUIAndroidLocationSensor;
public
constructor Create(ALocationSensor: TUIAndroidLocationSensor);
procedure onLocationChanged(P1: JObject); overload; cdecl;
procedure onLocationChanged(P1: JLocation); overload; cdecl;
procedure onLocationChanged(P1: JArrayList); overload; cdecl;
procedure onStatusChanged(P1: JString; P2: Integer; P3: JBundle); cdecl;
procedure onProviderEnabled(P1: JString); cdecl;
procedure onProviderDisabled(P1: JString); cdecl;
end;
Finally, we have added the following procedures:
Delphi Code:
procedure TUIAndroidLocationSensor.TLocationListener.onLocationChanged(P1: JObject);
begin
if TJNIResolver.IsInstanceOf(P1, TJArrayList.GetClsID) then
onLocationChanged(TJArrayList.Wrap(P1))
else if TJNIResolver.IsInstanceOf(P1, TJLocation.GetClsID) then
onLocationChanged(TJLocation.Wrap(P1));
end;
procedure TUIAndroidLocationSensor.TLocationListener.onLocationChanged(P1: JArrayList);
begin
onLocationChanged(TJLocation.Wrap(P1.get(P1.size-1)))
end;
Bookmarks