Ver Mensaje Individual
  #1  
Antiguo 28-10-2025
dani36652 dani36652 is offline
Miembro
 
Registrado: abr 2019
Posts: 78
Reputación: 8
dani36652 Va camino a la fama
Smile 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
Responder Con Cita