Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Desarrollo en Delphi para Android
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy


Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 20-12-2022
giantonti1801 giantonti1801 is offline
Miembro
 
Registrado: oct 2022
Posts: 143
Poder: 2
giantonti1801 Va por buen camino
no recibo push cuando la aplicación esta abierta

hola foro alguna idea porque no recibo la notificación push cuando la aplicación está abierta? recibo la notificación si la aplicación está cerrada o en segundo plano pero si está abierta no recibo nada

Código Delphi [-]
procedure TForminicio.FormCreate(Sender: TObject);
var
   PushService: TPushService;
   ServiceConnection: TPushServiceConnection;
   Notifications: TArray;
   const
   permRead = 'android.permission.READ_EXTERNAL_STORAGE';
   permWrite = 'android.permission.WRITE_EXTERNAL_STORAGE';
 begin
   VKAutoShowMode := TVKAutoShowMode.Always;
   VertScrollBox1.OnCalcContentBounds := CalcContentBoundsProc;

   PushService :=
   TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.FCM);
   ServiceConnection := TPushServiceConnection.Create(PushService);
   ServiceConnection.Active := True;
   ServiceConnection.OnChange := OnServiceConnectionChange;
   ServiceConnection.OnReceiveNotification := OnReceiveNotificationEvent;

   FDeviceId :=
   PushService.DeviceIDValue[TPushService.TDeviceIDNames.DeviceId];
   MemoLog.Lines.Add('DeviceID: ' + FDeviceId);
   MemoLog.Lines.Add('Ready to receive!');

   // Checks notification on startup, if application was launched fromcold start
   // by tapping on Notification in Notification Center
   Notifications := PushService.StartupNotifications;
   if Length(Notifications) > 0 then
   begin
       MemoLog.Lines.Add('-----------------------------------------');
       MemoLog.Lines.Add('DataKey = ' + Notifications[0].DataKey);
       MemoLog.Lines.Add('Json = ' + Notifications[0].Json.ToString);
       MemoLog.Lines.Add('DataObject = ' +
       Notifications[0].DataObject.ToString);
       MemoLog.Lines.Add('-----------------------------------------');
       
   end;
       LabelID_device.Text:=FDeviceId;



end;

Código Delphi [-]
procedure TForminicio.PushEvents1PushReceived(Sender: TObject;
  const AData: TPushData);
  var
  NC: TNotificationCenter ;
  N: TNotification;
  begin
  MemoLog.Lines.Add('Push recibido' + lineFeed);
  NC := TNotificationCenter.Create(Nil);
  N := NC.CreateNotification;
  try
    if NC.Supported  then
    begin
      N.Title := 'Tiene una VIsita';
      N.AlertBody := AData.Message;
      N.EnableSound := True;
      N.Number := 1;
      NC.ApplicationIconBadgeNumber := 1;
      NC.PresentNotification(N);
      
      
    end;

      finally
     NC.Free;
     N.Free;
  end;
 end;

Código Delphi [-]
procedure TForminicio.OnServiceConnectionChange(Sender: TObject;
  PushChanges: TPushService.TChanges);
var
  PushService: TPushService;
begin
  PushService := TPushServiceManager.Instance.GetServiceByName
    (TPushService.TServiceNames.FCM);
  if TPushService.TChange.DeviceToken in PushChanges then
  begin
    FDeviceToken := PushService.DeviceTokenValue
    [TPushService.TDeviceTokenNames.DeviceToken];
    MemoLog.Lines.Add('Firebase Token: ' + FDeviceToken);
    LabelToken.Text:= FDeviceToken;
    
    end;
    Log.d('Firebase device token: token=' + FDeviceToken);
  end;
  if (TPushService.TChange.Status in PushChanges) and
    (PushService.Status = TPushService.TStatus.StartupError) then
    MemoLog.Lines.Add('Error: ' + PushService.StartupError);
end;


procedure TForminicio.PushEvents1DeviceRegistered(Sender: TObject);
begin
  MemoLog.Lines.Add('Device Registrado:' +lineFeed);
end;

procedure TForminicio.PushEvents1DeviceTokenReceived(Sender: TObject);
begin
MemoLog.Lines.Add('Device Token recibido:' +lineFeed);
end;

procedure TForminicio.PushEvents1DeviceTokenRequestFailed(Sender: TObject;
  const AErrorMessage: string);
begin
    MemoLog.Lines.Add('Error:' +lineFeed);
    MemoLog.Lines.Add(AErrorMessage +lineFeed);
end;

estoy desarrollando con delphi 11 y la notificaciones push en firebase
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
saber si tabla esta abierta anubis Tablas planas 3 13-08-2007 15:04:59
buscar desde un dbedit cuando esta abierta una tabla bachoco MySQL 13 26-03-2007 23:39:18
Cuantas veces está abierta una aplicación pache Varios 8 02-03-2007 18:04:16
error al abrirse la aplicación cuando la base de datos esta en un 2003 server Giniromero Conexión con bases de datos 2 15-03-2005 10:09:35
Atrapar mensajes de Windows cuando la aplicación esta inactiva!! COCOL API de Windows 1 18-02-2005 06:27:49


La franja horaria es GMT +2. Ahora son las 14:11:25.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi