0

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?

Dalija Prasnikar
  • 27,212
  • 44
  • 82
  • 159
Lionking
  • 89
  • 1
  • 13
  • Shall we assume that the obvious approach of simply calling `FSensor.Stop` didn't work? You should say so. – Rob Kennedy Feb 25 '16 at 16:35
  • @RobKennedy I want to stop it from the host app. I have copied this procedure to the host app and modified to. Stop. But didn't work. – Lionking Feb 25 '16 at 16:52
  • 1
    Maybe I am stating the obvious but the host cannot stop the location sensor - only the android device can do that. So the host must send an instruction to the android device telling it to stop the location sensor, and you will need to write code to make the android device comply. – Dsm Feb 26 '16 at 10:21

0 Answers0