I use Delphi 10 Seattle Update 1 and I start the LocationSensor from android service. I use the following code:
procedure TAndroidServiceDM.StartLocationSensor;
var
FSensors: TSensorArray;
Sensor: TCustomSensor;
begin
TSensorManager.Current.Active := true;
FSensors := TSensorManager.Current.GetSensorsByCategory
(TSensorCategory.Location);
FSensor := nil;
for Sensor in FSensors do
begin
Log('Sensor ORD: ' + (ord(TCustomLocationSensor(Sensor).SensorType).ToString), []);
if (TCustomLocationSensor(Sensor).SensorType = TLocationSensorType.GPS) then
begin
FSensor := TCustomLocationSensor(Sensor);
Break;
end;
end;
if not Assigned(FSensor) then
Exit; { no location sensor is available }
{ start the sensor if it is not started }
if not FSensor.Started then
begin
FSensor.Start;
logi('sensor start');
end;
FSensor.OnLocationChanged := OnLocationChange;
end;
How can I stop the location sensor from the host application?