Andorid Studioを使ったAndoridアプリの作り方
5.広告の掲載<AdMob>
5.3 広告の組み込み
- コマンドプロンプトを開き、プロジェクトのフォルダで cordova plugin add com.admob.google と入力しEnterキーを押すと AdMob のプラグインがダウンロードされる。
※参考
- biorhythm\www\js の javascriptファイルを(ここでは main.js(cordovaをインストールした時に自動で作成される index.js
でも可))を開き、広告の表示を開始する為のコードを記述。
function onDeviceReady() {
document.removeEventListener('deviceready', onDeviceReady, false);
// Set AdMobAds options:
admob.setOptions({
publisherId: "ここにAdMobの広告ユニットIDを記述", // Required
interstitialAdId: "", // Optional
tappxIdiOs: "", // Optional
tappxIdAndroid: "", // Optional
tappxShare: "" // Optional
});
// Start showing banners (atomatic when autoShowBanner is set to true)
admob.createBannerView();
// Request interstitial (will present automatically when autoShowInterstitial is set to true)
admob.requestIntertitial();
}
document.addEventListener("deviceready", onDeviceReady, false)
- 実機で確認すると広告が表示される。