This is my code below which I use to enable GPS in Delphi. The problem is that the GPS automatically engages on the phone ONLY the first time the application is launched right after installation. After that, I always have to turn it on manually.
The question is, how to trigger at least a message that will make the user have to turn on the GPS himself ?
procedure TForm3.Button1Click(Sender: TObject);
const
permAccess = 'android.permission.ACCESS_FINE_LOCATION';
permCoarse = 'android.permission.ACCESS_COARSE_LOCATION';
begin
{$IFDEF ANDROID}
PermissionsService.RequestPermissions([permAccess],
procedure(const APermissions: TClassicStringDynArray; const AGrantResults: TClassicPermissionStatusDynArray)
begin
if (Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then
{ activate or deactivate the location sensor }
LocationSensor1.Active:=true
else
begin
ShowMessage('Problem');
end;
end);
{$ENDIF}
end;