admob icon indicating copy to clipboard operation
admob copied to clipboard

Problema ao exibir banner

Open Iv4nildo opened this issue 2 years ago • 6 comments

I implemented the plugin in a test application. implementation follows:

import { Injectable } from '@angular/core';
import { AdLoadInfo, AdMob, AdMobBannerSize, AdOptions, BannerAdOptions, BannerAdPluginEvents, BannerAdPosition, BannerAdSize, InterstitialAdPluginEvents } from '@capacitor-community/admob';

@Injectable({
  providedIn: 'root'
})
export class AdmobService {

  constructor() {
    this.initialize();
   }  

async initialize() {   
  AdMob.initialize({
    requestTrackingAuthorization: true,
    testingDevices: ['8864459307691256'],
    initializeForTesting: true,
  });
}

async banner() {
  AdMob.addListener(BannerAdPluginEvents.Loaded, () => {
    // Subscribe Banner Event Listener
  });

  AdMob.addListener(BannerAdPluginEvents.SizeChanged, (size: AdMobBannerSize) => {
    // Subscribe Change Banner Size
  });

  const options: BannerAdOptions = {
    adId: 'ca-app-pub-8864459307691256/2581366424',
    adSize: BannerAdSize.ADAPTIVE_BANNER,
    position: BannerAdPosition.BOTTOM_CENTER,
    margin: 0,
    //isTesting: true
    //npa: true
  };
  AdMob.showBanner(options);
}

async interstitial() {
  AdMob.addListener(InterstitialAdPluginEvents.Loaded, (info: AdLoadInfo) => {
    // Subscribe prepared interstitial
  });

  const options: AdOptions = {
    adId: 'ca-app-pub-8864459307691256/8520342408',
    //isTesting: true
    // npa: true
  };
  await AdMob.prepareInterstitial(options);
  await AdMob.showInterstitial();
}

}

on the Tab1 page it looked like this: tab1.page.html

<ion-header [translucent]="true">
  <ion-toolbar>
    <ion-title>
      Ads
    </ion-title>
  </ion-toolbar>
</ion-header>

<ion-content [fullscreen]="true">
 <ion-button expand="full" (click)="banner()">Banner ads</ion-button>
 <ion-button expand="full" (click)="interstitial()">Interstitial ads</ion-button>
</ion-content>

tab1.page.ts

import { UtilsService } from './../services/utils.service';
import { Component } from '@angular/core';

@Component({
  selector: 'app-tab1',
  templateUrl: 'tab1.page.html',
  styleUrls: ['tab1.page.scss']
})
export class Tab1Page {

  constructor(
    public utils: UtilsService
  ) {}

  interstitial(){
    this.utils.admobServices.interstitial()
  }

  banner(){
   this.utils.admobServices.banner();
  } 
}

AndroidManifest.xml:

<meta-data
 android:name="com.google.android.gms.ads.APPLICATION_ID"
 android:value="@string/admob_app_id"/>

MainActivity.java:

package com.oggi.cinepipoca;

import com.getcapacitor.BridgeActivity;
import android.os.Bundle;

public class MainActivity extends BridgeActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        registerPlugin(com.getcapacitor.community.admob.AdMob.class);
    }
}

strings.xml:

<?xml version='1.0' encoding='utf-8'?>
<resources>    
    <string name="admob_app_id">ca-app-pub-8864459307691256~153200000</string>
</resources>

this is the error that appears: for banner: image

for Interstitial this occurs: image

I need help trying to solve this problem

Iv4nildo avatar Jun 18 '22 16:06 Iv4nildo

Can you please write your message in English? You can use www.deepl.com

And please, format the code. I just see this on my phone and I can not understand anything.

Thanks!

distante avatar Jun 18 '22 16:06 distante

I updated the post

Iv4nildo avatar Jun 18 '22 17:06 Iv4nildo

Looks like you are calling the interstitial without it being prepared.

And the banner looks OK. But you can not use real ads on a non launched app.

distante avatar Jun 18 '22 18:06 distante

Okay, what would be the best way to call the interstitial, and the banner, not even the test one shows up.

Iv4nildo avatar Jun 18 '22 18:06 Iv4nildo

Parece que você está chamando o intersticia sem que ele esteja preparado.

E o banner parece bem. Mas você não pode usar anúncios reais em um aplicativo não lançado.

I did the configuration of the intertitial according to the plugin documentation and even then there was an error when preparing image

changed code

/**
   * ==================== Interstitial ====================
   */
     async prepareInterstitial() {
      this.isLoading = true;
  
      try {
        const result = await AdMob.prepareInterstitial(interstitialOptions);
        console.log('Intersticial preparado', result);
        this.isPrepareInterstitial = true;
        
      } catch (e) {
        console.error('Ocorreu um problema ao preparar o intersticial', e);
      } finally {
        this.isLoading = false;
      }
    }
  
  
    async showInterstitial() {
     await AdMob.showInterstitial()
        .catch(e => console.log(e));
  
      this.isPrepareInterstitial = false;
    }
  
    /**
     * ==================== /Interstitial ====================
     */

Iv4nildo avatar Jun 18 '22 19:06 Iv4nildo

@Iv4nildo You got message "No ad config." in your screen shot. This is not plugin error. Please check your admob settings.

Google search "admob error no ad config" may help you. Thanks.

rdlabo avatar Jul 04 '22 09:07 rdlabo

Use test ids https://developers.google.com/admob/android/test-ads?hl=en

EmreAka avatar Mar 04 '23 17:03 EmreAka