cordova用プラグイン admob plus で、androidアプリに広告を表示させたい
下記のようにマニュアル通りに設定したのですが、広告が表示されません。
何が悪いのかご教示いただきたくお願いいたします。
admobへのアプリ登録は完了しており、アプリケーションIDは有効な状態です。
環境 (他のプラグインは正常に動作します)
Windows10
android studio 4.0
GradleJDK = jre1.8
JAVA_HOME = jdk_15.02
ANT_HOME= apache-ant-1.10.12
admob_plus のドキュメント抜粋
Installation
https://admob-plus.github.io/docs/cordova/installation
Getting Started
https://admob-plus.github.io/docs/cordova
App Open Ad
https://admob-plus.github.io/docs/cordova/ads/app-open
Banner Ad
https://admob-plus.github.io/docs/cordova/ads/banner
当方が行った作業
cordova create test_app
cd test_app
cordova plugin add cordova-admob-plus --variable APP_ID_ANDROID=ca-app-pub-3250964248608123~1234567890 →私の個人のアプリケーションID(ADMOB提供ID)
cordova platform add android
ここで config.xml 内の <widget></wiget>の間に下記を追記
(Installationにて指示があるため)
<platform name="android"> <allow-intent href="market:*" /> </platform>
次に、index.js に 書き足す
index.js デフォルト
document.addEventListener('deviceready', onDeviceReady, false); function onDeviceReady() { // Cordova is now initialized. Have fun! console.log('Running cordova-' + cordova.platformId + '@' + cordova.version); document.getElementById('deviceready').classList.add('ready'); }
index.js 書き足し後
Getting Started
App Open Ad
Banner Ad
を追記
(ca-app-pub-3940256099942544/3419835294 は admob open時のテストID)
(ca-app-pub-3940256099942544/6300978111 は admob バナーのテストID)
document.addEventListener('deviceready', onDeviceReady, false); function onDeviceReady() { // Cordova is now initialized. Have fun! console.log('Running cordova-' + cordova.platformId + '@' + cordova.version); document.getElementById('deviceready').classList.add('ready'); } document.addEventListener('deviceready', async () => { // Obtain user consent first await admob.start() // or start loading ads // Load ads here }, false) document.addEventListener('deviceready', async () => { const ad = new admob.AppOpenAd({ adUnitId: 'ca-app-pub-3940256099942544/3419835294', }) ad.on('load', (evt) => { // evt.ad }) document.addEventListener( 'resume', async () => { // NOTE `resume` event is triggered when dismissing interstitial ads or by other reasons, // make sure to add logic to control when to display the ad. if (!await ad.show()) { await ad.load() }) }, false, ) document.addEventListener('deviceready', async () => { banner = new admob.BannerAd({ adUnitId: 'ca-app-pub-3940256099942544/6300978111', }) banner.on('impression', async (evt) => { await banner.hide() }) await banner.show() }, false)
cordova build android
cordova run
結果
ビルド&ランは成功し、無事success表示されます。
index.htmlも表示されますが、広告だけが表示されません
私の作業のどこに誤りがあるかご教示いただきたくお願いいたします。
あなたの回答
tips
プレビュー