admob
admob copied to clipboard
Problema ao exibir banner
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:
for Interstitial this occurs:
I need help trying to solve this problem
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!
I updated the post
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.
Okay, what would be the best way to call the interstitial, and the banner, not even the test one shows up.
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
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 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.
Use test ids https://developers.google.com/admob/android/test-ads?hl=en