Home gpsLocation with androidservice in fulltime in DELPHI
Reply: 0

gpsLocation with androidservice in fulltime in DELPHI

user2068
1#
user2068 Published in April 26, 2018, 5:14 pm

Try this code, but my application closes, I want to get the GPS location every so often but it does not work for now I'm visualizing with udp client.

type
  TAndroidServiceDM = class(TAndroidService)
    function AndroidServiceStartCommand(const Sender: TObject;
      const Intent: JIntent; Flags, StartId: Integer): Integer;
  private
    { Private declarations }
    FLocationManager: JLocationManager;
    FLocationManagerService: JObject;
    FLocationListener: JLocationListener;

  protected

  public
    { Public declarations }
  end;

var
  AndroidServiceDM: TAndroidServiceDM;

implementation

{ %CLASSGROUP 'FMX.Controls.TControl' }

uses AndroidApi.JNI.App;

{$R *.dfm}

procedure send_udp(ip: string; puerto: Integer; datos: string);
var
  send_udp: TIdUDPClient;
begin
  send_udp := TIdUDPClient.Create(nil);
  send_udp.Host := ip;
  send_udp.Port := puerto;
  send_udp.Send(datos);
  send_udp.Free;
end;

function TAndroidServiceDM.AndroidServiceStartCommand(const Sender: TObject;
  const Intent: JIntent; Flags, StartId: Integer): Integer;
  var
  iter:JIterator;
  location : JLocation;
begin

  Result := TJService.JavaClass.START_STICKY;
  FLocationManagerService := TAndroidHelper.Context.getSystemService(
    TJContext.JavaClass.LOCATION_SERVICE);
  FLocationManager := TJLocationManager.Wrap(
    (FLocationManagerService as ILocalObject).GetObjectID);

  if FLocationManager.isProviderEnabled(
    TJLocationManager.JavaClass.GPS_PROVIDER) then
  begin
    FLocationListener := TJLocationListener.Create;
      FLocationManager.requestLocationUpdates(TJLocationManager.JavaClass.GPS_PROVIDER,
        0, 0, FLocationListener, TJLooper.JavaClass.getMainLooper);


  end;
  location := FLocationManager.getLastKnownLocation(TJLocationManager.JavaClass.GPS_PROVIDER);

   send_udp('127.0.0.1',5555,'Servicio Iniciado'+location.getLatitude.ToString);

end;

end.

if someone can help me with this code or some other to send the gps location

I need to send the position every 10 minutes.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.317412 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO