Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Android: Anuncios Intersticiales de forma Nativa con Delphi (https://www.clubdelphi.com/foros/showthread.php?t=97795)

dani36652 28-10-2025 18:52:03

Android: Anuncios Intersticiales de forma Nativa con Delphi
 
Hola qué tal estimados.
El día de hoy les traigo este ejemplo de cómo implementar anuncios intersticiales de Google Admob de manera nativa en Android con Delphi.

La idea es simple, se usa una librería aar con toda la lógica nativa y desde delphi solo se usan poquitas lineas de código para hacer uso de los anuncios, ejemplo:
Código Delphi [-]
unit UMain;

interface

uses
  UInterstitialAd,
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.Controls.Presentation, FMX.StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    procedure OnAdLoaded;
    procedure OnAdFailed(const ErrorMessage: string);
    procedure OnAdClosed;
  public
    { Public declarations }
    FInterstitialAd: TInterstitialAd;
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.FormCreate(Sender: TObject);
begin
  FInterstitialAd:= TInterstitialAd.Create(Self);
  FInterstitialAd.OnAdLoaded:= OnAdLoaded;
  FInterstitialAd.OnAdFailed:= OnAdFailed;
  FInterstitialAd.OnAdClosed:= OnAdClosed;
  FInterstitialAd.TestMode:= True;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  FInterstitialAd.Show;
end;

procedure TForm1.OnAdClosed;
begin
  Label1.Text:= 'Interstitial Ad Closed';
end;

procedure TForm1.OnAdFailed(const ErrorMessage: string);
begin
  Label1.Text:= 'Interstitial Ad Load Failed: ' + ErrorMessage;
end;

procedure TForm1.OnAdLoaded;
begin
  Label1.Text:= 'Interstitial Ad Loaded';
end;

end.

Como pueden ver, solo hay que crear el objeto, mostrar su anuncio e incluso es posible acceder a sus eventos.

El repositorio con las unidades necesarias y un ejemplo está en el siguiente link: https://github.com/dani36652/Delphi-...tialAd-Example

Neftali [Germán.Estévez] 29-10-2025 08:38:09

^\||/^\||/^\||/
Gracias por el código.

ElKurgan 03-11-2025 11:55:51

Muchas gracias por el aporte

Saludos


La franja horaria es GMT +2. Ahora son las 03:25:55.

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