Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Cross-Platform-Entwicklung (https://www.delphipraxis.net/91-cross-platform-entwicklung/)
-   -   Android Service startet nicht (https://www.delphipraxis.net/212079-android-service-startet-nicht.html)

erich.wanker 14. Dez 2022 13:02

Android Service startet nicht
 
Hallo,
Delphi 10.4.2

Ich hab ein bisserl mit der Demo rumgespielt und sie minimal verändert - seitdem startet der service nicht mehr

Demo: C:\Users\Public\Documents\Embarcadero\Studio\21.0\ Samples\Object Pascal\Multi-Device Samples\Device Sensors and Services\AndroidNotificationServiceDemo
  • Die NotificationApp habe ich nicht angerührt
  • Die NotificationService habe ich abgeändert mit:
- Neue procedure "starte_loop" - es soll kontinuierlich der rückgabewert einen php als Notification ausgegeben werden.

- bei LaunchNotification(nachricht:String) habe ich den string "Nachricht" hinzugefügt


Was ist da falsch?
Danke und liGrü
Erich


Delphi-Quellcode:
procedure TNotificationServiceDM.start_loop;
  var
    atask : Itask;
    H : TIdHTTP;
    SS : TStringStream;
    url : string;
    dummy : Boolean;
    Ergebnis:String;
  begin
    dummy := false;
    atask := Ttask.create(
      procedure( )

        begin

          REPEAT
          begin
            sleep( 30000 );
            url := ' mein server /test.php?a=2&b=3'; // Liefert echo "Ergebnis ist 6"
            H := TIdHTTP.create( nil );
            try
              SS := TStringStream.create;
              try
                H.Get( url, SS );
                Ergebnis := SS.DataString;
                LaunchNotification(Ergebnis);
              finally
                SS.Free;
              end;
            finally
              H.Free;
            end;

          end;
          UNTIL dummy = true;
        end );

    atask.Start;

  end;

function TNotificationServiceDM.AndroidServiceStartCommand(
  const Sender  : TObject;
  const Intent  : JIntent;
  Flags, StartId : Integer ) : Integer;

  begin

    start_loop;
    //LaunchNotification(Ergebnis);
    //JavaService.stopSelf;
    //Result := TJService.JavaClass.START_STICKY;

  end;

procedure TNotificationServiceDM.LaunchNotification(nachricht:String);
  var
    MyNotification : TNotification;

  begin

    MyNotification := NotificationCenter1.CreateNotification;
    try
      MyNotification.Name := 'ServiceNotification';
      MyNotification.Title := 'Android Service Notification';
      MyNotification.AlertBody := nachricht;
      MyNotification.FireDate := IncSecond( Now, 8 );
      NotificationCenter1.ScheduleNotification( MyNotification );
    finally
      MyNotification.Free;
    end;

  end;

jaenicke 14. Dez 2022 13:21

AW: Android Service startet nicht
 
Dass deine Funktion AndroidServiceStartCommand nun einen undefinierten Rückgabewert hat, sollte dir der Compiler eigentlich mitteilen. Woher soll denn das Betriebssystem wissen, dass dein Service einer ist, der weiter laufen soll?


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:12 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz