Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Cross-Platform-Entwicklung (https://www.delphipraxis.net/91-cross-platform-entwicklung/)
-   -   Von angezeigter Notification zum Programm wechseln? (https://www.delphipraxis.net/196766-von-angezeigter-notification-zum-programm-wechseln.html)

sko1 18. Jun 2018 07:20

Von angezeigter Notification zum Programm wechseln?
 
Hallo,

in einer Android-App zeige ich oben in der Taskleiste eine Notification an (z.B. 2 Stunden vor einem Termin).

Nun möchte ich, wenn der Benutzer auf diese Notification klickt, das zugehörige Programm starten.

Leider finde ich keinerlei Ansatz, wie das realisiert werden könnte :-(

Ciao
Stefan

knaeuel 29. Jun 2018 12:10

AW: Von angezeigter Notification zum Programm wechseln?
 
ich poste mal einfach etwas Quellcode. Der fett gedruckte Teil ist das, was du suchst.

Delphi-Quellcode:
procedure TFormX.HandleAlert;
var //Notifications:
    MyNotification:TNotification;
begin
  MyNotification:=NotificationCenter1.CreateNotification;
  MyNotification.Name:='Message'; //taucht auf Android nicht auf
  MyNotification.Title:='Notification'; //Taucht als Titelzeile (fett) auf
  //AlertBody ist für iOS obligatorisch
  MyNotification.AlertBody:='Alarmmeldung!'; //taucht als 2. Zeile (nicht fett) auf
  MyNotification.Number:=usercfg.n_notifications; //funktioniert i-wie nicht wie erwartet
  MyNotification.EnableSound:=false;

  {$IFDEF iOS}
  //nur für iOS?
  NotificationCenter1.ApplicationIconBadgeNumber:=usercfg.n_notifications;
  {$ENDIF}
hier die beiden Zeilen, die für dich hauptsächlich interessant sind:
Delphi-Quellcode:
  //beim Klicken auf die Notification soll sich die App öffnen:
  MyNotification.HasAction := True;
  MyNotification.AlertAction := 'Open App';
und noch der Rest der Procedure
Delphi-Quellcode:
  //ZUM SCHLUSS ABSCHICKEN

  //Anzeige mit gesetztem Firedate
  //z.B. Fired in 10 seconds: MyNotification.FireDate := Now + EncodeTime(0, 0, 10, 0);
  //MyNotification.FireDate:=now;
  //NotificationCenter1.ScheduleNotification(MyNotification);

  //sofortige Anzeige
  try
    NotificationCenter1.PresentNotification(MyNotification);
  finally
    MyNotification.DisposeOf;
  end;
end;
Ich hoffe, es hilft und funzt :)

sko1 29. Jun 2018 13:13

AW: Von angezeigter Notification zum Programm wechseln?
 
Hallo Wolfgang,

vielen Dank, das

Delphi-Quellcode:
  //beim Klicken auf die Notification soll sich die App öffnen:
  MyNotification.HasAction := True;
  MyNotification.AlertAction := 'Open App';
war genau der fehlende Punkt :-)

Ciao
Stefan


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:43 Uhr.

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