Luiz Alves
Luiz Alves

Reputation: 2645

Capturing push notifications android

I am using Delphi XE7. I have an android mobile application, receiving push notiications. Sometimes, I have ten or more push icon notifications on top bar. When the user click in only one notification icon, I´d like to get all notifications to show into my app.

I did the next procedure to capture all them, but is not working because it´s capturing only the push message clicked.

Does someone could help me about this problem?

    var NotificationCenter: TNotificationCenter;
        PushEvents1:TPushEvents
    //this procedure is called in the OnActivate event of app the main form.
    procedure getAllNotfications;
    begin
     AServiceConnection:=PushEvents1.PushConnection;
     if AServiceConnection = nil then exit;
     LNotifications:=AServiceConnection.Service.StartupNotifications;
     K:=Length(LNotifications);
     for i:= low(LNotifications) to high(LNotifications) do begin
         LNotification := TPushData.Create;
         LNotification.Load(LNotifications[i].Json);
         try
          if (Assigned(LNotification) and  ((LNotification.GCM.Message<>'') or (LNotification.Message<>''))) then begin 
            Memo1.Lines.Add('Enter by Notification Click: ' + LNotification.GCM.Message);

          end;
         finally
          LNotification.DisposeOf;
          LNotification:=nil;
         end;
     end;
    end;

Regards, Luiz

Upvotes: 2

Views: 4536

Answers (1)

mjn
mjn

Reputation: 36654

Your app can be notified about all incoming notifications if it registers a service as shown here: https://stackoverflow.com/a/11332278/80901

In the service you can collect all data of incoming notifications, and store them locally (for example in a database).

When the user selects one of the notifications from the display, your application can collect the received notifications from your local storage and present them in your app.

Upvotes: 1

Related Questions