Delphi LocationSensor如何从主机应用关闭?

时间:2016-02-25 10:49:47

标签: android delphi delphi-10-seattle

我使用Delphi 10 Seattle Update 1,我从android服务启动LocationSensor。我使用以下代码:

 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; 

如何从主机应用程序中停止位置传感器?

0 个答案:

没有答案