我使用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;
如何从主机应用程序中停止位置传感器?