In Android 12, my Android app (written in Delphi) can no longer access the Jlocation
after this is supplied by onLocationChanged
. It works fine in earlier versions.
The location system is running from a Foreground Service, which is started by the main App. ACCESS_BACKGROUND_LOCATION
has been set. User "Location Allow All The Time" has been set.
It works perfectly normal in Android 10.
The Foreground Service crashes with this error:
java_vm_ext.cc:579] JNI DETECTED ERROR IN APPLICATION: can't call double android.location.Location.getLatitude() on instance of java.util.ArrayList
06-30 06:54:13.222: A/ack.SARTrackAp(4421): java_vm_ext.cc:579] in call to CallDoubleMethodA
06-30 06:54:13.222: A/ack.SARTrackAp(4421): java_vm_ext.cc:579] from java.lang.Object com.embarcadero.services.SARTrackServiceProxyInterface.dispatchToNative(java.lang.String, java.lang.Object[], long)
06-30 06:54:13.626: A/ack.SARTrackAp(4421): runtime.cc:669] Runtime aborting...
In fact, any call to the JLocation
causes a crash. But, the onLocationChanged
is generated by Android itself, so how can the supplied JLocation
be invalid?
For example:
procedure TLocationListener.onLocationChanged(location: JLocation);
var
Accuracy: double;
begin
if location.hasAccuracy then // <<< It crashes the Service here already
begin
LocalLog('onLocationChanged: hasAccuracy');
Accuracy := location.getAccuracy;
LocalLog('onLocationChanged: Accuracy='+Accuracy.ToString);
end else LocalLog('onLocationChanged: NOT hasAccuracy');
end;